Forum Moderators: open

Message Too Old, No Replies

Why can't I make vertical align work?

Can't get text to be vertically centered with image

         

Trace

9:47 pm on Jan 7, 2008 (gmt 0)

10+ Year Member



I've seriously wasted a whole afternoon on something that I thought would be pretty simple to accomplish.

Let me start off by saying I have absolutely no control over the generated HTML. All I can do is apply CSS styles to the page. The HTML must remain the way it is shown below but I have full control on the Style Sheets.

All I want to do is vertically center the text with the images, like this;

img img img
img img img
img img img txt txt txt txt
img img img
img img img

I need to do this to all 4 list items which all use the same classes. (so I can't just add different margins to the individual items)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>

<style>
#navigation ol{
list-style:none;
padding:0;
margin:0;
}
#navigation ol li{
width:150px;
display:block;
float:left;
}
#navigation ol li img{
width:30px;
height:50px;
float:left;
}
#navigation ol li span{
display:block;
}
</style>

<div id="navigation">
<ol>
<li>
<a href="#">
<img src="1.png"/>
<span>Lorem ipsum</span>
</a>
</li>
<li>
<a href="#">
<img src="2.png"/>
<span>Lorem ipsum dolor sit amet</span>
</a>
</li>
<li>
<a href="#">
<img src="3.png"/>
<span>Lorem </span>
</a>
</li>
<li>
<a href="#">
<img src="4.png"/>
<span>Quisque semper, quam non ultricies viverra, justo nulla porttitor leo</span>
</a>
</li>
</ol>
</div>

</body>
</html>

If someone could point me in the right direction I would be extremely grateful. Thanks in advance!

looteras

4:25 am on Jan 8, 2008 (gmt 0)

10+ Year Member



<style>img{vertical-align: middle;}</style>
<img src=img.jpg>Text

Trace

2:14 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



Thanks Looteras - but all that does is

img img img
img img img
img img img txt txt txt txt txt txt txt
img img img
img img img
txt txt txt txt txt txt txt

Doesn't help me.

Trace

2:27 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



With the display:block on the span, vertical-align:middle on the image gives me this;

img img img
img img img
img img img txt txt txt
img img img txt txt txt
img img img txt txt txt

I need the text to be centered so that doesn't work.

Why is this so damned hard?

penders

3:06 pm on Jan 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Don't have display:block; on the SPAN, keep both the IMG and SPAN inline. That is, don't float the IMG either (as this makes it a block level element). Then apply your:
img {vertical-align:middle;}

Trace

6:06 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



Hi penders,

As I mentioned above, this is the result which is just not acceptable;

img img img
img img img
img img img txt txt txt txt txt txt txt
img img img
img img img
txt txt txt txt txt txt txt

Trace

6:11 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



When using display:table-cell on the span I get exactly what I need. Problem is IE doesn't like it and just ignores it. 100% of my visitors use IE this is obviously not an option.

I haven't been able to find something that works in the same fasion for IE. Any ideas?

Trace

8:02 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



Thanks guys but it looks like there is no solution and I have moved on. I actually had a new webpart developed and now it renders tables instead of the div with a list.

Can't win'em all I guess.