How to center something vertically within a box?, CSS |
How to center something vertically within a box?, CSS |
NovaArgon |
Nov 24 2008, 10:42 AM
Post
#1
|
Always Need To Learn A New Code Group: Members Posts: 265 Joined: 10-June 07 From: South Carolina Member No.: 3,057 |
Hello this is a box that holds my nave bar
CODE #nav_container { height: 68px; width: 100%; margin: 0 auto; background: url(http://www.gamerunion.com/forum/styles/IR_bright/imageset/menubar.png) repeat-x; } I am trying to center this navbar vertically do you see what I need to change in my css? its already in the center horizontally CODE #navbar { height: 37px; width: 500px; margin: 0 auto; } Thanks for the help |
NovaArgon |
Nov 24 2008, 11:35 AM
Post
#2
|
Always Need To Learn A New Code Group: Members Posts: 265 Joined: 10-June 07 From: South Carolina Member No.: 3,057 |
This seems to be working ok so I guess I got it. Thanks for the help
#navbar { height: 37px; width: 500px; margin: 0 auto; padding-top: 15px; } Thanks for the help |
Frederiek |
Nov 24 2008, 04:17 PM
Post
#3
|
Programming Fanatic Group: Members Posts: 5,146 Joined: 23-August 06 From: Europe Member No.: 9 |
Just put margin: auto auto; and everything should center.
See also http://www.w3.org/Style/Examples/007/center |
Christian J |
Nov 25 2008, 12:01 PM
Post
#4
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
This seems to be working ok so I guess I got it. Thanks for the help #navbar { height: 37px; width: 500px; margin: 0 auto; padding-top: 15px; } Note that this relies on the padding and text height adding up with the #navbar height. If the user changes text size or if the text line-breaks it may fall apart. Why not use equal top and bottom padding/margin, and let the height of both boxes vary depending on text size? |
Christian J |
Nov 25 2008, 12:03 PM
Post
#5
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
Just put margin: auto auto; and everything should center. Not vertically? QUOTE Yes but the bottom example: http://www.w3.org/Style/Examples/007/center#vertical Alas "display: table-cell" is not supported by MSIE yet. |
NovaArgon |
Nov 28 2008, 11:36 AM
Post
#6
|
Always Need To Learn A New Code Group: Members Posts: 265 Joined: 10-June 07 From: South Carolina Member No.: 3,057 |
Thanks for the help. I'll try out and see but i'm using buttons so its not effected by users changing the text size.
|
pandy |
Nov 28 2008, 09:01 PM
Post
#7
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
Since both boxes have a a hight and they won't contain anything that can expand that height, why not position the inner box relative the outer?
|
Lo-Fi Version | Time is now: 23rd April 2024 - 12:33 PM |