我必须将所有元素置于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