The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> How to center something vertically within a box?, CSS
NovaArgon
post 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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
NovaArgon
post 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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post 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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Nov 25 2008, 12:01 PM
Post #4


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(NovaArgon @ Nov 24 2008, 05:35 PM) *

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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Nov 25 2008, 12:03 PM
Post #5


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(Frederiek @ Nov 24 2008, 10:17 PM) *

Just put margin: auto auto; and everything should center.

Not vertically? unsure.gif

QUOTE

Yes but the bottom example: http://www.w3.org/Style/Examples/007/center#vertical tongue.gif

Alas "display: table-cell" is not supported by MSIE yet.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
NovaArgon
post 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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post 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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 23rd April 2024 - 12:33 PM