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 です。次に、固定幅のコンテンツ ボックスが 1 つあります。その固定幅のボックスを中央に配置する必要がありますが、太陽の下では何もできません。私は何時間も頭を悩ませてきました。トピックに関するすべてのチュートリアルと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;、要素を削除してhttp://dl.dropbox.com/u/17927147/StackOverflow/Screen%20shot%202011-03-15%20at%2013.59.12.png#mainを追加することだけでしたmargin:0 auto;

于 2011-03-14T13:19:39.087 に答える