I have number of of child div
s in a parent div
. It may be minimum 2 to maximum 8. I have kept the width of child div
s 25% fixed. The problem is when there are 2 or 3 child div
s, then first 50% or 75% of parent div
is used to display these div
s. But I want to use center 50% or 75% of parent div
to display these div
s. In case there are more than 4 child div
s 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/