[英]Center “left floated” content (text-align: center; wont work)
#content
{
background-color: red;
text-align: center;
}
#content div
{
float: left;
background-color: green;
padding: 10px;
margin: 10px;
}
<div id="content">
<div>AAAAA</div>
<div>AAAAA</div>
<div>AAAAA</div>
<div>AAAAA</div>
<div>AAAAA</div>
<div>AAAAA</div>
<div>AAAAA</div>
<div>AAAAA</div>
</div>
<div style="clear: both;"></div>
http://jsfiddle.net/nTLny/ http://jsfiddle.net/nTLny/
here the usual code. 这是通常的代码。 I want to achieve the following:
我要实现以下目标:
so the aligned div goes center. 因此对齐的div居中。
#content div
{
float: none;
display:inline-block;
background-color: green;
padding: 10px;
margin: 10px;
}
Try it... 试试吧...
#content div {
background-color: #008000;
display: inline-block;
margin: 10px;
padding: 10px;
}
your css: 您的CSS:
#content{
background-color:white ;
text-align: center;
width:300px; /*giving it a width so it actually adjust to your sample image 300px seems to be close to yours*/
}
#content div
{
display: inline-block; /*second adjustment you need as "Abhineet" has mentioned*/
background-color: green;
padding: 10px;
margin: 10px;
}
#bottom {
float:right;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.