Struggling to get things to behave.
I have a dynamic list of images on a responsive site. The layout is generated where images can be in rows/columns or columns rows.
This example is close but the paired images don't align at the bottom as the browser resizes...
<div style="width:100%;">
<div style="width:60%; display: flex; margin-left: auto; margin-right: auto;">
<div id="outterrow" style="width:100%; float:left; display: flex; padding-bottom: 1.15%; ">
<div id="column" style="float: left;overflow: hidden;background-color: inherit;width: 49.35%;">
<div id="row" style=" padding-right: 2.330294%; "><img title="2.jpeg" src="https://i.postimg.cc/Xv5YsYv7/2.jpg" sizes="100vw" width="100%">
</div>
</div>
<div id="column" style="float: left;overflow: hidden;background-color: inherit;width: 50.65%;">
<div id="row" style=" "><img title="1.jpg" src="https://i.postimg.cc/B6cQG7Dr/1.jpg" sizes="100vw" width="100%"> </div>
</div>
</div>
</div>
<div style="width:60%; display: flex; margin-left: auto; margin-right: auto;">
<div id="outterrow" style="width:100%; float:left; display: flex; padding-bottom: 1.15%; ">
<div id="column" style="float: left;overflow: hidden;background-color: inherit;width: 100%;">
<div id="row" style=" "><img title="3.jpg" src="https://i.postimg.cc/ZnbYYPxC/3.jpg" sizes="100vw" width="100%"> </div>
</div>
</div>
</div>
<div style="width:60%; display: flex; margin-left: auto; margin-right: auto;">
<div id="outterrow" style="width:100%; float:left; display: flex; padding-bottom: 1.15%; ">
<div id="column" style="float: left;overflow: hidden;background-color: inherit;width: 43.55%;">
<div id="row" style=" padding-right: 2.640643%; "><img title="5.jpg" src="https://i.postimg.cc/bwsJ2Tcn/5.jpg" sizes="100vw" width="100%"> </div>
</div>
<div id="column" style="float: left;overflow: hidden;background-color: inherit;width: 56.45%;">
<div id="row" style=" "><img title="4.jpg" src="https://i.postimg.cc/XJ07m6ZK/4.jpg" sizes="100vw" width="100%"> </div>
</div>
</div>
</div>
</div>
I've experimented with object-fit but Safari seems to fall apart.
EDIT: for reference here is an example of the problem.
The height and width of an image can be set using height and width attribute. The height and width can be set in terms of pixels. The <img> height attribute is used to set the height of the image in pixels. The <img> width attribute is used to set the width of the image in pixels.
Put the image's maximum width to 100% with the max-width property. Set the flex-basis property of the "image" class to specify the initial main size of your image. Choose the font size of your text with the help of the font-size property. Use the padding-left property to set the padding space on the text's left side.
You could of course use background images instead of the HTML img-tag. If you can access the image height I would recommend to fill that one in dynamically via JavaScript or PHP (or whatever setup you have). I placed a spacer-div inside the wrapping container, which could be used for that purpose.
#wrap_all {
width:100%;
}
#inner {
max-width:1210px;
padding:0 50px;
margin:0 auto;
}
.flexrow {
display:flex;
justify-content: space-between;
background:#f5f5f5;
flex-wrap:wrap;
}
.flexcol {
flex:0 0 49%;
background-repeat: no-repeat;
background-size: cover;
background-position:top center;
margin-bottom: 2%;
}
.spacer.height-80vh {
height:80vh;
}
.flexcol.fullwidth {
flex:0 0 100%;
}
<div id="wrap_all">
<div id="inner">
<div class="flexrow">
<div class="flexcol" style="background-image: url('https://i.postimg.cc/Xv5YsYv7/2.jpg')">
<div class="spacer height-80vh"></div>
</div>
<div class="flexcol" style="background-image: url('https://i.postimg.cc/B6cQG7Dr/1.jpg')">
<div class="spacer height-80vh"></div>
</div>
<div class="flexcol fullwidth" style="background-image: url('https://i.postimg.cc/ZnbYYPxC/3.jpg')">
<div class="spacer height-80vh"></div>
</div>
<div class="flexcol" style="background-image: url('https://i.postimg.cc/bwsJ2Tcn/5.jpg')">
<div class="spacer height-80vh"></div>
</div>
<div class="flexcol" style="background-image: url('https://i.postimg.cc/XJ07m6ZK/4.jpg')">
<div class="spacer height-80vh"></div>
</div>
</div>
</div>
</div>
This is called pixel rounding, or the sub-pixel problem, and it's a basic math issue:
You have two containers with a relative width of ~50% sitting inside of a responsive parent. What should happen when that parent element's width is an odd number? Say 211 pixels. 50% of 211px is 105.5px. BUT, there is no such a thing as .5px - Your screen just can't turn on only half of that little light bulb that physically defines a pixel. The browser rounds it to a larger or smaller number.
If you look close, the layout is composed by:
There's just no solution to insert images of varying dimensions inside of divs of varying dimensions inside of a % oriented layout. That is just too much pixel rounding to account for. If you look close, this layout is "broken" 100% of the time... it's either leaving blank pixels or shrinking/distorting the images inside.
Whatever hack anybody present will either generate that little blank pixel, distort the images (again, they don't have the same height or width) or secretly hide pixels from the image somewhere.
Now, a quick hack for the specific snipet you've presented:
img {
vertical-align: bottom;
}
.column {
position: relative;
}
.column:after {
content: '';
display: block;
position: absolute;
bottom: 0;
width: 100%;
background: #fff;
height: 6px; /* this will fake padding bottom */
}
.row {
padding-left: 6px;
}
<div style="width:100%;">
<div style="width:60%; display: flex; margin-left: auto; margin-right: auto;">
<div id="outterrow" style="width:100%; float:left; display: flex;">
<div class="column" style="float: left;overflow: hidden;background-color: inherit;width: 49.35%;">
<div class="row" ><img title="2.jpeg" src="https://i.postimg.cc/Xv5YsYv7/2.jpg" sizes="100vw" width="100%">
</div>
</div>
<div class="column" style="float: left;overflow: hidden;background-color: inherit;width: 50.65%;">
<div class="row" style=" "><img title="1.jpg" src="https://i.postimg.cc/B6cQG7Dr/1.jpg" sizes="100vw" width="100%"> </div>
</div>
</div>
</div>
<div style="width:60%; display: flex; margin-left: auto; margin-right: auto;">
<div id="outterrow" style="width:100%; float:left; display: flex;">
<div class="column" style="float: left;overflow: hidden;background-color: inherit;width: 100%;">
<div class="row" style=" "><img title="3.jpg" src="https://i.postimg.cc/ZnbYYPxC/3.jpg" sizes="100vw" width="100%"> </div>
</div>
</div>
</div>
<div style="width:60%; display: flex; margin-left: auto; margin-right: auto;">
<div id="outterrow" style="width:100%; float:left; display: flex; ">
<div class="column" style="float: left;overflow: hidden;background-color: inherit;width: 43.55%;">
<div class="row"><img title="5.jpg" src="https://i.postimg.cc/bwsJ2Tcn/5.jpg" sizes="100vw" width="100%"> </div>
</div>
<div class="column" style="float: left;overflow: hidden;background-color: inherit;width: 56.45%;">
<div class="row" style=" "><img title="4.jpg" src="https://i.postimg.cc/XJ07m6ZK/4.jpg" sizes="100vw" width="100%"> </div>
</div>
</div>
</div>
</div>
Again, no "solution" exists under these conditions, just hacks with drawbacks.
*To be fair with browsers, they are doing such a good job handling pixel rounding that most developers never even realize this is an issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With