rossnaumov — 2010-03-11T02:46:25-05:00 — #1
I'm trying to centre the text in this menu but IE doesn't want to play the game. It’s centres in chrome, safari and FF. Any ideas?
philiptoop — 2010-03-11T10:11:05-05:00 — #2
I am assuming that you mean centers vertically!
I have viewed it in IE8 and it does center vertically but I also get a list disc. Switch the browser to emulate IE7 and the text is positioned at the top.
In chrome the <p> tag has a margin-top of 1em set by the default attributes of the browser and that is why it appears to center vertically.
rossnaumov — 2010-03-11T17:31:17-05:00 — #3
Thanks for your help.
Yes i mean center vertically.
"In chrome the <p> tag has a margin-top of 1em set by the default attributes of the browser and that is why it appears to center vertically"
So to fix this if remove <p> tag and margin-top of 1em this will position text at top in chrome. I then start again with re-positioning?
philiptoop — 2010-03-12T04:03:45-05:00 — #4
Alternatively in the style sheet set margin-top: to 1em for p.
All browsers including IE should then appear correct.
There is a chance that it will not make any difference at all in IE and there is something else going on. But we can investigate further if that is the case.
paulob — 2010-03-12T07:40:27-05:00 — #5
Usually to center non wrapping text in a block like that the easiest way is to set the line-height to the same as the height of the block that you want to centre it in. You don't have to guess then as long as you know the height.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Of course the same effect can be done with trial and error by adding margins or padding to move the element into position.:)
rossnaumov — 2010-03-14T18:02:01-04:00 — #6
*** Thanks PhilipToop. I removed the <p> altogether then used margin-top: which worked a treat! Thanks for your help mate!
*** Paul O'B - What a great tip! Thanks, I'll give it a go. I thought if you did this the text would sit to the bottom... why does it center it?
ryanreese — 2010-03-14T18:18:34-04:00 — #7
It just does lol :). You'd have to understand the inline formatting model to really understand why.
Basically if the line height matches the height then it will vertically center it.
Though it doesn't work for more then 1 line of text
rossnaumov — 2010-03-14T18:55:48-04:00 — #8
Awsome!! Thanks heaps
rossnaumov — 2010-03-14T19:09:44-04:00 — #9
ryanreese — 2010-03-14T19:27:56-04:00 — #10
If you are asking if line-height method will work cross browser then yes :).
rossnaumov — 2010-03-14T19:37:50-04:00 — #11
Yes thank you
rossnaumov — 2010-03-14T19:39:28-04:00 — #12
By the way... congrats on the CSS Guru of the Year!! Nice work!
ryanreese — 2010-03-14T23:42:49-04:00 — #13