Jump to content

[SOLVED] centering a div inside another div


Stickybomb

Recommended Posts

ok i have a liquid/fixed layout with header,footer and 2 columns. i am wanting to center a div inside of the right column, with no luck so far.

 

This is the basic layout that i have.

 

//CSS

body
{
	margin: 0;
	padding: 0;
}

#header
{
	height: 100px;
	background-color: #000;
}

#nav
{
	float: left;
	width: 180px;
	height: auto;
	background-color: #666;
}
#content
{
	margin-left: 10px;
                margin-top: 10px;
	height: auto;
	background-color: #fff;
}

#footer
{
	clear: both;
	height: 30px;
	background-color: #000;
}

//html

<div id="header"></div>
<div id="nav"></div>
<div id="content">
<div id="box">
</div>
<div id="footer"></div>

 

any help would greatly be appriciated!

 

thanks

Link to comment
Share on other sites

Well the first thing that you need to do is close your content div like:

<div id="header"></div>
<div id="nav"></div>
<div id="content">
<div id="box">
</div>
</div>
<div id="footer"></div>

 

I'll assume that you are trying to center "box" right? If so you need to do this:

#box{
width:200px;
margin:0px auto;
}

 

and that should center it for you...you do need a width in there though.

 

Hope that helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.