Having a fixed-height, variable width grid of 'oversized' images (simplified: 2 images only, different only by orientation. In reality, these have various sizes and aspect ratios) inside a flex
container (simplified: body
) yields different results depending on the browser:
body {
display: flex;
}
.grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: 50px;
}
.grid>img {
width: 100%;
max-height: 100%;
border: 1px solid red;
object-fit: cover;
}
<body>
<div >
<img alt="portrait"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHEAAACWCAMAAADe4ZfYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAALHUExURf/////j4/ ysv EhP9YWP9DQ/8 Pv9NTf9jY/93d/ Jif Skv Zmf env/m5v goP9dXf89Pf9XV/ Li/ 4uP/l5f/7 / hof/f3/ Kiv9BQf9SUv Wlv/b2//9/f/a2v9RUf/z8/9GRv9VVf qqv/19f9HR/ iov/09P/i4v8/P/ QkP/r6//e3v9KSv 3t/9kZP/n5/9paf/Fxf9LS//4 P9AQP 8vP/ /v/Hx/ Xl//6 v Vlf/29v9ycv9WVv/R0f jo//S0v9ERP9tbf9qav/5 f9ubv/w8P9PT//g4P87O//Ly//Kyv86Ov/T0/85Of/v7/EvL7 Njb /v7 MjE0ICAAAAFINDf9MTP9oaP dnR0dHSkpKf bm/9vb/ cnP/Ozv88PP rq/9cXP vv/o6P9/f/ fn/ Bgf9CQv/h4f9gYP/V1f9aWv9ra//Cwv/u7v/x8f9fX2lpaYCAgH9/f1ZWVv/U1P9 fv 1tdLS0qysrP/d3f9ZWf9UVP pqf Tk/98fP/AwP/8/P9nZ/97e/ MjP amv9xcf9FRf/X1//Bwf96ev9ISP/39/ 5uf99ff oqP9iYv/MzP/Gxv kpP Hh/ YmP Pj//IyP/Jyf9sbP srP/q6v/y8v 9vf94eP/p6SAXFyohIagCAgMAAAQAAKsDA/ trYocHJYAAAIAAJgAAJcpKXkAAI0AAAEAAI8AACopKX0AAJIAAJQAAHIAAJ0AAAYAAJ8AAGAAALQAABAAALUAAEMAAM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6d27f unnj rW/ SK jpT9z7LwgbdRHTSjZgwOzagZg0Mzasbg0Iz/4L BqMm/uG0NDQ0NDQ2N/zEA/wEU/2eZMbAjoQAAAABJRU5ErkJggg==" />
<img alt="landscape"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAABxCAMAAAAAnqrqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAALHUExURf/////9/f/a2v pqf98fP9RUf9AQP8 Pv9SUv9nZ/97e/ MjP Tk/ amv dnf Xl/ QkP EhP9xcf9dXf9FRf89Pf9GRv9kZP Skv/Bwf/x8f/ /v/d3f Wlv9UVP88PP9fX//AwP/r6//8/P/29v/X1/96ev9ISP9BQf 5uf/U1P9/f/9ZWf goP/j4//39//Fxf99ff9VVf/09P/u7v 1tf/5 f/f3/ Kiv8/P//Hx//b2/9ra/9CQv bm//MzP9qav kpP/V1f9aWv/Cwv Hh/86Ov YmP/4 P/h4f9gYP/Ozv Pj/87O/ jo/ Bgf9DQ//z8/9ERP/Jyf vv fn//g4P9vb//y8v9cXP/o6P srP rq//q6v94eP/6 v cnP9HR//i4v Zmf/m5v/Kyv/w8P9MTP/p6f trf/l5fEvL1INDSkpKSohIasDA5cpKSopKcrKyr MjAAAAAQAAJgAAHkAAL /v/85Of/S0gIAAI8AAH0AAP/n5wEAAJQAAHIAAAMAAJ8AAGAAAP9PT/ 3twYAALUAAEMAAP9ubhAAAMMAACYAACcAAMEAAAsAAE8AAP/e3pAAAFsAAP9ycgkAAMIAACAAADMAALEAAIoAAP Li/ VlcYAAA4AAFZWVqysrNiDg8hAQP9paf 8vICAgP9LS39/f/9mZv9NTf/c3P9KSv93d//s7P iov91df 7u/ qqv/19f/Nzf hof/7 /9XV/ ysv 4uH94eP9YWH9XV38yMoAREY4AAP9jY6QAALgGBv JickMDNITE9gZGf ent4eHqUAAIB4eP 6umlpadLS0uyYmOBXV4kAAP9WVv/R0aEAAAwAAP9tbbQAAP/Ly50AAP/T05IAAI0AAL Nj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SarUNGtQqeRohAaXW5AGDF/GZfoQEhO8tllZpUGvMswgJKLVYznPoUgVP6/nEo0UcyovIBl5Alyp4WsFdCAlItYa/iC5V8LRcaJOQajW9hC5V8LS2ok1CqjX7ZXSpgqe1G20SUq3WV9ClCp7WdrRJSLXGv4ouVfC0XkObhFQr7XV0qYKnNQ5tElIt9ga6VMHTio5L7gOt1pvoUgVP6y20SWi13kaXKv5H1ZL0vSXpT6Kkn1tOf8q/gy5V8LQk/Z0o6R2EpPdbkt6dGrqXF6eV8y66VMHTkvTJR9LnREmfqll2NUIcSq1sw2MQU QcsWnPQohDWC0T41uSjgbKOnZqYKRZULVMjTSzPMfG5d8zM4sx6NQshr/QjFaDk3M xi9i6hkyIVruGmWGzHi1WKsz84k 5WiiWmx3itlXIVpLzM6 sr5t nPVIrQszFVLOrPPujOTt/QcrT3v2 aDD2PtHnSpQluL9Y9C4GrZx9qqEVbrol1j85G1NTas6mMZVyQRr99aY3X9FvNUSrnajX0SJFsb CkCH30ttoNsJeVnSHxSaLHPidadrkXSIJVW8yrlyV w1uov7K7SZR2uL0Vr9X5le01z5JdQYEisVs/XAlaAMxYKDInUWv6NkPXyite3eLUAer8TtLtA2Yvx/Q C PGnn5F0 QXfWZ9fNwvbudKEJITyvWL2 fgt7YzTYZaIXVE5 43K2qYuIOMeMsZK99rbcdf5G6JoNnba2J/4O91W653FNRZ3cwb/QKQhJOPeVwUpdworSLmvWqFsvcvYLnTXn3 Zqax9hv42sGf/nwacOYiUf EghmN/D4KxfwHWVQ8n8y9KWgAAAABJRU5ErkJggg==" />
</div>
</body>
The expected result (both same size, aspect ratio preserved, cover) in Chrome 108.x:
[]
and the result in FF 108.x:
[]
I tried playing with various 'settings' (such as object-fit: cover
, aspect-ratio: 1 / 1
, nesting the images / the grid in div
s with e.g. display: block
, using reset.css or normalize.css, ...) but could not find a working solution.
What do I need to do to get the Chrome behaviour in FF?
CodePudding user response:
Since width of 50px seems to matter, use grid-template-columns instead of -rows, and for the image use aspect-ratio: 1; and if you want object-fit: cover; to prevent image distortions
CodePudding user response:
Since width
of 50px seems to matter, use grid-template-columns
instead of -rows, and for the image use aspect-ratio: 1;
and if you want object-fit: cover;
to prevent image distortions
.grid {
display: grid;
grid-template-columns: 50px;
}
.grid>img {
width: 100%;
aspect-ratio: 1;
object-fit: cover;
border: 1px solid red;
}
<div >
<img alt="width of img > height of row" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkBAMAAACCzIhnAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAADUExURf///6fEG8gAAAAJcEhZcwAADsEAAA7BAbiRa 0AAAAcSURBVFjD7cEBDQAAAMKg909tDwcEAAAAAByoARPsAAFwJuooAAAAAElFTkSuQmCC"
/>
</div>