I have the following code where the images are fetched from the database. It keeps going breaking the DIV
and overflows
. What I want is when the images reach the end of the DIV
it should break and start a new line. But I have no idea as how to achieve this. Please help me guys.
<div class="inline-flex">
<?php while($faf = $prooq->fetch()){ extract($faf); ?>
<div class="image-container"> <img class="myThumb" id="myImg" src="proofs/<?php echo $pr_image; ?>" alt="" width="160" height="100">
<div class="image-text">shreyansh ($8.75)<br>
<span><?php echo date('jS M, Y (h:i a)', strtotime($pr_uptime)); ?></span></div>
</div>
<div id="myModal" class="modal"> <span class="close">×</span> <img class="modal-content" id="modalImg">
<div id="caption"></div>
</div>
<?php } ?>
</div>
.image-container {
width: 163px;
height: 100px;
padding: 0px 0px 65px 0px;
font-size: 12px;
text-align: center;
font-family: Verdana, Arial, Helvetica, sans-serif;
margin-right: 13px;
}
.image-text {
margin-top: 5px;
}
.image-text span {
color: #ddd;
font-size: 9px;
}
.inline-flex {
width: 100%;
display: inline-flex;
}
I found the answer to my solution. Added an extra DIV with class .proof-container
with property position: relative;
and wrapped all elements inside it and added a property float: left;
to .image-container
. That's it. Below is the code:
CSS:
.image-container {
width: 197px;
height: 120px;
padding: 0px 0px 65px 0px;
font-size: 12px;
text-align: center;
font-family: Verdana, Arial, Helvetica, sans-serif;
margin-right: 10px;
float: left;
}
.proof-container {
width: 100%;
position: relative;
}
HTML:
<div class="proof-container">
<?php while($faf = $prooq->fetch()){ extract($faf); ?>
<div class="image-container">
<img class="myThumb" id="myImg" src="proofs/<?php echo $pr_image; ?>" alt="" width="160" height="100">
<div class="image-text"><?php echo $mem_uname; ?> ($8.75)<br>
<span><?php echo date('jS M, Y (h:i a)', strtotime($pr_uptime)); ?></span></div>
</div>
<div id="myModal" class="modal"> <span class="close">×</span> <img class="modal-content" id="modalImg">
<div id="caption"></div>
</div>
<?php } ?>
</div>
Try using display : table
.inline-flex {
width: 100%;
display: table;
}
You need to set display: inline-block; float: left;
to .image-container
.image-container {
width: 163px;
height: 120px;
padding: 0px 0px 65px 0px;
font-size: 12px;
text-align: center;
font-family: Verdana, Arial, Helvetica, sans-serif;
margin-right: 13px;
display: inline-block;
float: left;
}
.image-text {
margin-top: 5px;
}
.image-text span {
color: #ddd;
font-size: 9px;
}
.inline-flex {
width: 100%;
}
<div class="inline-flex">
<div class="image-container"> <img class="myThumb" id="myImg" src="http://lorempixel.com/output/nature-q-c-200-200-3.jpg" alt="" width="160" height="100">
<div class="image-text">shreyansh ($8.75)<br>
<span>date('jS M, Y (h:i a)', strtotime($pr_uptime));</span></div>
</div>
</div>
<div class="image-container"> <img class="myThumb" id="myImg" src="http://lorempixel.com/output/nature-q-c-200-200-3.jpg" alt="" width="160" height="100">
<div class="image-text">shreyansh ($8.75)<br>
<span>date('jS M, Y (h:i a)', strtotime($pr_uptime));</span></div>
</div>
<div class="image-container"> <img class="myThumb" id="myImg" src="http://lorempixel.com/output/nature-q-c-200-200-3.jpg" alt="" width="160" height="100">
<div class="image-text">shreyansh ($8.75)<br>
<span>date('jS M, Y (h:i a)', strtotime($pr_uptime));</span></div>
</div>
<div class="image-container"> <img class="myThumb" id="myImg" src="http://lorempixel.com/output/nature-q-c-200-200-3.jpg" alt="" width="160" height="100">
<div class="image-text">shreyansh ($8.75)<br>
<span>date('jS M, Y (h:i a)', strtotime($pr_uptime));</span></div>
</div>
<div class="image-container"> <img class="myThumb" id="myImg" src="http://lorempixel.com/output/nature-q-c-200-200-3.jpg" alt="" width="160" height="100">
<div class="image-text">shreyansh ($8.75)<br>
<span>date('jS M, Y (h:i a)', strtotime($pr_uptime));</span></div>
</div>
<div class="image-container"> <img class="myThumb" id="myImg" src="http://lorempixel.com/output/nature-q-c-200-200-3.jpg" alt="" width="160" height="100">
<div class="image-text">shreyansh ($8.75)<br>
<span>date('jS M, Y (h:i a)', strtotime($pr_uptime));</span></div>
</div>
</div>