我必須將所有元素置於div.to_left_60
中。我需要解決方案,它將適用於那裏的所有元素。 我爲此設置了text-align: center
。它適用於文本,但不適用於我的ul元素。我試圖玩邊緣和absolute/relative
,但沒有運氣。div中的中心元素
ul.problem是我必須以此div爲中心的元素。從jsfiddle你看到白色背景不居中。
HTML
<div class="to_left_40">gtestsetes</div>
<div class="to_left_60">
<p>gtestsetes</p>
<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTvZsT7cLwPFCC0joFhZoi6OylhGaIVHBPYn--PrH3nzZdMwH0grA" width="265px" />
<ul class="problem">
<li>fsfsd</li>
<li>fsfsd</li>
</ul>
<ul>
<li>fsfsd</li>
<li>fsfsd</li>
</ul>
CSS
ul {
list-style: none;
text-align: justify;
background-color: yellow;
}
ul.problem li {
list-style-type: none;
display: block;
width: 245px;
height: 164px;
padding: 14px 10px 0 10px;
background-color: white;
background-repeat: no-repeat;
text-align: center;
font-size: 18px;
}
.to_left_40 {
float: left;
width: 40%;
background-color: red;
}
.to_left_60 {
float: left;
width: 60%;
background-color: green;
text-align: center;
}
的jsfiddle:http://jsfiddle.net/qVTQ4/
編輯:(SOLLUTION)
這有助於:
ul.problem li{margin:0 auto;}
我已經修改了這個sollution:
.to_left_60 * {
margin:0 auto;
}
嗯。有沒有一種方法可以像下面這樣重寫它:.to_left_60> {margin:0 auto;}我不知道如何正確編寫它:(所有元素的margin:0 auto都在.to_left_60中) – renathy