GilloD
GilloD

Reputation: 571

I need to center a fixed width div that resides inside a liquid width div

I've got code that looks like this:

<div id="wrapper"> <!--Liquid -->

  <div id="header"> <!--Liquid-->
    <img src="logo.png">
  </div> <!--End header -->
 <div id="bg_hold"> <!--Holds a background, Liquid -->


 <div id="main"> <!--Fixed-->
   <div id="l_col">
     lcol
   </div>

   <div id="r_col">
      rcol
   </div>
 </div> <!--End main -->
</div><!--End bg_hold-->
</div> <!--End wrapper -->

enter code here

So what we're looking at here is a bunch of liquid divs designed to expand with the resolution. Then there's one content box that's a fixed width. I need to center that fixed width box and nothing under the sun will do it. I have been beating my head for hours, I have looked at every tutorial and SO question on the topic. Nothing does it. Here's the CSS, it's a smidge janky because of all the fixes I've attempted to implement:

body{
font-family: Tahoma,Josefin Sans,Arial, Helvetica, sans-serif;
font-size:12px;
}


#wrapper{
width:100%; /*Creating a liquid layout for the wrapper un-centers the main div */
clear:both;
overflow:hidden;
margin:0 auto;
}

#header{
position: relative;
float:left;
width:100%;
background-image: url("img_v3/header_bg.png");
text-align:center;
}

#bg_hold{
width:100%;
overflow:hidden;
background-image: url("img_v3/body_bg.png");
}


#main{
width:645px;
text-align:center;
position: relative;
float:left;
z-index: 1000;
-webkit-box-shadow: #BBB 0px 0px 10px;
background: rgba(255, 255, 255, 0.699219);
border-bottom-left-radius: 10px 10px;
border-bottom-right-radius: 10px 10px;
border-top-left-radius: 10px 10px;
border-top-right-radius: 10px 10px;

text-align: justify;
}

#l_col{
width: 380px;
float:left;
margin-top: 20px;
margin-right: 30px;
margin-left: 20px;
margin-bottom: 20px;
}

#r_col{
width:185px;
float:left;
margin-top: 20px;
margin-right: 20px;
margin-left: 10px;
margin-bottom: 20px;
}

The very moment I moved the 'wrapper' close from a fixed width to a liquid width, it uncentered the "main" element. I've tried everything. What m I missing?

Upvotes: 1

Views: 3271

Answers (1)

mylesagray
mylesagray

Reputation: 8869

Is this what you were after:

JSFiddle Demo

All I did was remove float:left; on the #main element and add margin:0 auto; http://dl.dropbox.com/u/17927147/StackOverflow/Screen%20shot%202011-03-15%20at%2013.59.12.png

Upvotes: 1

Related Questions