Solved

list item ignores vertical-align when using list-style-image

Posted on 2008-10-08
7
4,141 Views
Last Modified: 2012-05-05
I'm building an unordered list and I wanted to use small images for the bullet markers.  The images are different but they are all the same size.  (60x45)  So far so good.  Silly me, I was expecting the browser to render the item text in the middle of the 45px box.  Doh!  IE sucks the text up to the top and Firefox nails it to the bottom.  I've tried vertical-align as in the code sample but no joy.  Is there a solution to this?
#browse ul li {

		margin-left: 100px;

		vertical-align: middle;

	}

	#browse ul li#ea {

		list-style-image: url('images/earring-bullet.gif');

	}

	#browse ul li#br {

		list-style-image: url('images/bracelet-bullet.gif');

	}

	#browse ul li#ne {

		list-style-image: url('images/necklace-bullet.gif');

	}

...

	<div id="browse">

		<h3>

			<span>Browse</span>

		</h3>

		<ul>

			<li id="ea">Earrings</li>

			<li id="br">Bracelets</li>

			<li id="ne">Necklaces</li>

		</ul>

	</div>

Open in new window

0
Comment
Question by:peter-blackwood
  • 3
  • 2
  • 2
7 Comments
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22675807
Problem is a 60x45 image is too big for the average <LI> item.  You will have to put either the image in a SPAN tag and position that relative, or else style the list tags to have no padding and some offset, like

LI  {padding:0px; margin:0px; position:relative; top:10px; }  or something along those lines.
0
 
LVL 42

Accepted Solution

by:
David S. earned 125 total points
ID: 22676241
list-style-image is handled inconsistently cross-browser.  I recommend you use a background image and background-repeat:no-repeat instead.
0
 
LVL 1

Author Comment

by:peter-blackwood
ID: 22685888
Thanks scratchyboy, I tried your LI suggestion but it positions everything, including the marker, and does not affect the position of the text relative to the marker.  I will try Kravimir's solution when I get a minute - think I'm going to have to dump the <ul><li> approach entirely and go with a table or successive <div>s.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 42

Expert Comment

by:David S.
ID: 22685982
"li" elements can be styled the same way that "div" elements can. Don't abandon semantic markup for something like this.
0
 
LVL 44

Assisted Solution

by:scrathcyboy
scrathcyboy earned 125 total points
ID: 22688959
The graphic AND the text needs to be all enclosed by the one <LI>  graphic and text </LI>  tag.
0
 
LVL 1

Author Comment

by:peter-blackwood
ID: 22693933
The background image is what did it.  There is a backround-position-y with value center, but no equivalent for list-style image.  Thanks to both of you.  Here is what I ended up with:
	#browse ul li {

		margin-left: 50px;

		list-style: none;

		font-family: mistral, cursive;

		font-size: 24pt;

	}

	#browse ul li span {

		margin-left: 70px;

	}

	#browse ul li#ea {

		background: transparent url('images/bracelet-bullet.gif') no-repeat center left ; 

	}

	#browse ul li#br {

		background: transparent url('images/bracelet-bullet.gif') no-repeat top left ; 

	}

	#browse ul li#ne {

		background: transparent url('images/bracelet-bullet.gif') no-repeat top left ; 

	}

...

	<div id="browse">

		<h3>

			<span>Browse</span>

		</h3>

		<ul>

			<li id="ea"><span>Earrings</span></li>

			<li id="br"><span>Bracelets</span></li>

			<li id="ne"><span>Necklaces</span></li>

		</ul>

	</div>

Open in new window

0
 
LVL 1

Author Comment

by:peter-blackwood
ID: 22693957
Sorry, those last three were supposed to be:
	#browse ul li#ea {

		background: transparent url('images/earring-bullet.gif') no-repeat center left ; 

	}

	#browse ul li#br {

		background: transparent url('images/bracelet-bullet.gif') no-repeat center left ; 

	}

	#browse ul li#ne {

		background: transparent url('images/necklace-bullet.gif') no-repeat center left ; 

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
targeting between desktop and responsive menu 3 30
Problem to page 4 74
How can I do a Select All on this page? 8 36
form button worked now it doesnt anymore 9 41
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now