1

我的代码如下所示:

<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。然后是一个固定宽度的内容框。我需要将那个固定宽度的盒子居中,在阳光下什么都做不了。我已经打了几个小时的头,我查看了有关该主题的每个教程和 SO 问题。什么都没有。这是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;
}

在我将“包装器”从固定宽度移动到液体宽度的那一刻,它使“主要”元素不居中。我什么都试过了。我错过了什么?

4

1 回答 1

1

这就是你所追求的:

JSFiddle 演示

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

于 2011-03-14T13:19:39.087 回答