Reputation: 6197
#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>
here the usual code. I want to achieve the following:
so the aligned div goes center.
Upvotes: 0
Views: 66
Reputation: 21
your 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;
}
Upvotes: 1
Reputation: 632
Try it...
#content div {
background-color: #008000;
display: inline-block;
margin: 10px;
padding: 10px;
}
Upvotes: 1
Reputation: 115135
Text-align center will work if you use display:inline-block
instead of using float
CSs
#content div
{
display: inline-block;
background-color: green;
padding: 10px;
margin: 10px;
}
Upvotes: 2
Reputation: 1763
#content div
{
float: none;
display:inline-block;
background-color: green;
padding: 10px;
margin: 10px;
}
Upvotes: 1