Reputation: 139
So I am trying to make it so that these 4 div's are side by side but centered using margin: auto;
Here is it WITHOUT inline-block;
HTML:
<section class="stats">
<div class="box1">
<h5>Online Users</h5>
</div>
<div class="box1">
<h5>Online Users</h5>
</div>
<div class="box1">
<h5>Online Users</h5>
</div>
<div class="box1">
<h5>Online Users</h5>
</div>
</section>
CSS:
.stats {
padding: 15px;
}
.box1 {
margin: auto;
width: 20%;
background-color: #b0e0e6;
}
Here it is WITH inline-block; (for some reason not centering with margin)
HTML:
<section class="stats">
<div class="box1">
<h5>Online Users</h5>
</div>
<div class="box1">
<h5>Online Users</h5>
</div>
<div class="box1">
<h5>Online Users</h5>
</div>
<div class="box1">
<h5>Online Users</h5>
</div>
</section>
CSS:
.stats {
padding: 15px;
}
.box1 {
margin: auto;
width: 10%;
background-color: #b0e0e6;
display: inline-block;
}
Thanks for the help!
Upvotes: 3
Views: 112
Reputation: 243
Add text-align:center;
to .box1
ie
.box1 {
margin: auto;
width: 20%;
background-color: #b0e0e6;
text-align:center;
}
Upvotes: 2
Reputation: 635
To center text, you just need to use style "text-align:center" for box1 class. see code below
.box1 {
margin: auto;
width: 20%;
background-color: #b0e0e6;
text-align:center;
}
Upvotes: 1
Reputation: 2510
You want to use text-align: center;
so the modified css would look like this:
.stats {
padding: 15px;
text-align: center;
}
.box1 {
margin: auto;
width: 10%;
background-color: #b0e0e6;
display: inline-block;
text-align: center;
}
See fiddle: http://jsfiddle.net/ug2YZ/3/
Hope this helps.
Upvotes: 4