Forum Moderators: not2easy
<style>
.imgList {
float: left;
width: 150px;
height: 260px;
padding: 20px;
margin: 0 5px 10px 5px;
border: 1px solid #E3E3E3;
overflow: hidden
}
@media only screen and (max-width: 660px) {
.imgList { padding: 4px !important }
}
</style>
<div class="imgList">
<img src="image.jpg">
</div> @media only screen and (max-width: 660px) {
.imgList {
box-sizing: border-box;
width: 50% !important;
padding: 4px !important
}
} Padding is inside the container, it is deducted from the px size of the container so a padding of 4px reduces the available width by 8px.
<style>
.mobileFlex { display: inline }
.imgList {
float: left;
width: 150px;
height: 260px;
padding: 20px;
margin: 0 5px 10px 5px;
border: 1px solid #E3E3E3;
overflow: hidden
}
/* Mobile only */
@media only screen and (max-width: 660px) {
.mobileFlex {
display: flex !important;
box-sizing: border-box
}
.imgList {
width: auto !important;
flex-basis: 50%;
padding: 4px !important;
}
}
</style>
<div class="mobileFlex">
<div class="imgList">
<img src="image.jpg">
</div>
<div class="imgList">
<img src="image.jpg">
</div>
</div>
<div class="mobileFlex">
<div class="imgList">
<img src="image.jpg">
</div>
<div class="imgList">
<img src="image.jpg">
</div>
</div> $counter = 0;
$next_row = $sth->fetch();
while (list($foo, $bar) = mysqli_fetch_row($sth)) {
$mobileFlex = $counter / 2;
if ($mobileFlex == intval($mobileFlex))
echo <<<EOF
<div class="mobileFlex">
EOF;
echo <<<EOF
<div class="imgList">
<img src="image.jpg">
</div>
EOF;
$next_row = $sth->fetch();
if ($mobileFlex != intval($mobileFlex) || !$next_row)
echo <<<EOF
</div>
EOF;
$counter++;
} I don't see any indication of the css for "img" but if the image size is not controlled using max-width: 100% then it may want to take more than the width you have allowed for it. Setting img: max-width to 100% insures that the image resizes to fit the container.
Padding is inside the container, it is deducted from the px size of the container so a padding of 4px reduces the available width by 8px.