我需要居中一个固定宽度div,它位于液体宽度div内

时间:2011-03-14 13:08:01

标签: html css center fixed liquid

我的代码看起来像这样:

<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

所以我们在这里看到的是一堆液体div,旨在扩展分辨率。然后有一个固定宽度的内容框。我需要将固定宽度的盒子放在中心位置,阳光下的任何东西都不会。我已经打了好几个小时,我已经看过每个教程和关于这个主题的问题。什么都没有。这是CSS,由于我试图实现的所有修复,这是一个微不足道的小事:

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;
}

当我将'包装纸'从固定宽度移动到液体宽度时,它就不再是“主要”元素。我已经尝试了一切。我错过了什么?

1 个答案:

答案 0 :(得分:1)

这就是你所追求的:

JSFiddle Demo

我所做的就是删除float:left;元素上的#main并添加margin:0 auto; http://dl.dropbox.com/u/17927147/StackOverflow/Screen%20shot%202011-03-15%20at%2013.59.12.png