简体   繁体   English

居中“左浮动”内容(文本对齐:居中;不起作用)

[英]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居中。

Text-align center will work if you use display:inline-block instead of using float 如果使用display:inline-block而不是float则文本对齐中心将起作用

JSfiddle 的jsfiddle

CSs CS的

#content div
{
display: inline-block;
background-color: green;
padding: 10px;        
margin: 10px;
}
    #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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM