The code below shows the intended mode when I resize the window in Chrome 60 and in Firefox 55 (but not in iOS Safari 10.3, this is most likely another question why it works poorly in Safari).
html, body { width: 100%; height: 100%; padding: 0; margin: 0; border: 0; background-color: lightgrey; } .container { box-sizing: border-box; width: 100%; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: repeat(3, calc((60vh - 12px)/3)); height: 60vh; border: 3px solid yellow; padding: 3px; } .tile { } img { box-sizing: border-box; display: block; object-fit: contain; width: 100%; height: 100%; margin: 0; border: 0; padding: 3px; }
<div class="container"> <div class="tile"> <img src="/img/acf5ea011898a35d901f674bc9d1b5b7.png" alt="." /> </div> <div class="tile"> <img src="/img/acf5ea011898a35d901f674bc9d1b5b7.png" alt="." /> </div> <div class="tile"> <img src="/img/acf5ea011898a35d901f674bc9d1b5b7.png" alt="." /> </div> <div class="tile"> <img src="/img/acf5ea011898a35d901f674bc9d1b5b7.png" alt="." /> </div> <div class="tile"> <img src="/img/acf5ea011898a35d901f674bc9d1b5b7.png" alt="." /> </div> <div class="tile"> <img src="/img/acf5ea011898a35d901f674bc9d1b5b7.png" alt="." /> </div> </div>
It is important that the aspect ratio of the images (2: 1)

saved. I would also expect:
grid-template-rows: 1fr 1fr 1fr;
or
grid-template-rows: auto auto auto;
makes images placed on grid lines, but none of them does. FROM:
grid-template-rows: repeat(3, calc((60vh - 12px)/3));
I get the desired behavior. How can I avoid the very development of mathematics? In other words, what should I do to work grid-template-rows: 1fr 1fr 1fr; (or something similar)?
It is already difficult to determine the height of a container element in CSS on a real page. The goal is to solve this problem using CSS mesh diagrams; no javascript and no background images.
Update: I initially ruled out hacking for two reasons.
I thought (due to some misunderstandings) that the url background image should be in the CSS file, but this is not the case: I can use inline styles and have it in HTML.
He felt like a hacker. Seeing how difficult and random it is with nested flexible containers nested inside the grid container to make it work on Safari, I just resorted to hacking the background image, since it is much cleaner and works in all tested browsers (Chrome, Firefox, Safari).
In the end, this is not an accepted answer that helped solve my problem.
html css image css3 css-grid
Ali
source share