I have number of of child divs in a parent div. It may be minimum 2 to maximum 8. I have kept the width of child divs 25% fixed. The problem is when there are 2 or 3 child divs, then first 50% or 75% of parent div is used to display these divs. But I want to use center 50% or 75% of parent div to display these divs. In case there are more than 4 child divs then I want to display first row of parent row without any change and want to use centered 25% for 5th div, centered 50% for 5th and 6th and centered 75% for 5th, 6th and 7th div.
HTML:
<div class="container">
<p>Block1</p>
<div class="banner">
<div class="block1">
<img src="hoels.png" />
<p>Banquet Halls</p>
</div>
<div class="block1">
<img src="hoels.png" />
<p>Resorts</p>
</div>
<div class="block1">
<img src="hoels.png" />
<p>Hotels</p>
</div>
---------------------------
---------------------------
---------------------------
</div>
</div>
CSS:
.container{
width:100%;
margin:0 auto;
max-width:991px;
}
.banner{
padding:20px;
}
.block1{
float:left;
width:33%;
text-align:center;
}
.block1 img{
width:100%;
max-width:100px;
}
Fiddle: https://jsfiddle.net/7fpt4m5e/2/