Reputation: 1324
How do I center these objects in a way that looks more natural and responsive to how many there are?
The layout is a single div with multiple divs for each gauge. I used .float-left to get them to go to the next row.
Could I get them to be positioned like this if there are 5:
****O****O****O****
******O*****O******
And like this if there are 4:
**O**O**O**O**
Upvotes: 0
Views: 70
Reputation: 9471
I believe to do this you will have to use either JavaScript or CSS Flexbox. Flexbox is only supported in modern browsers though.
Here is a simple example using flexbox:
<div class="wrapper">
<div></div>
<div></div>
<div></div>
</div>
.wrapper {
margin-bottom: 1em;
display: flex;
justify-content: space-around;
}
.wrapper > div {
width: 100px;
height: 100px;
background: blue;
border: solid 2px red;
}
Of course, to make this work in all modern browsers, your CSS will look more like:
.wrapper {
margin-bottom: 1em;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: space-around;
-webkit-justify-content: space-around;
-moz-box-pack: space-around;
-ms-flex-pack: space-around;
justify-content: space-around;
}
.wrapper > div {
width: 100px;
height: 100px;
background: blue;
border: solid 2px red;
}
Upvotes: 1