2

I am trying to vertically align text in IE7 is proving to be a PITA without the css options of display: table; and display: table-cell;

It is for a navigation that looks similar to this:

<ul>
    <li><a href="#"><span>Text covers one line</span></a></li>
    <li><a href="#"><span>Text covers two lines, problem occurs</span></a></li>
</ul>

CSS:

ul li a{ display: table; zoom: 1; width: 240px; height: 30px;}
ul li a span{ width: 200px; display: table-cell; zoom: 1; vertical-align: middle; padding: 0 30px 0 20px; } 

Works on newer browsers. I can get the text to center easily with only one line of text, but when it goes to two I can't seem to get anything working.

theorise
  • 7,245
  • 14
  • 46
  • 65
  • You realise your spans aren't properly closed? – Finnnn Sep 27 '11 at 13:18
  • If closing the span properly doesn't fix it would you mind using JavaScript? That's the only way I can think of without some hacky CSS classes on each
  • and some backend logic to count letters.
  • – Bill Criswell Sep 27 '11 at 13:32
  • This question may help - http://stackoverflow.com/questions/4785871/css-vertical-align – Finnnn Sep 27 '11 at 13:34
  • Sorry the span was just a typo, it isn't broken in my markup. The question you posted works for a single line of text (setting the line-height to the same height of the div), but you can imagine the results when there are two lines of text... – theorise Sep 27 '11 at 13:36
  • Also in response to JS, I guess I wouldn't mind using that. I'd prefer it over a huge excess of markup. – theorise Sep 27 '11 at 13:48