Responsive image

I want I image to be responsive but Its not https://codepen.io/tobygxgr-the-sans/pen/PwoBZQV
No description
6 Replies
Tok124 (CSS Nerd)
Tok124 (CSS Nerd)ā€¢6d ago
It works as expected, when the image is very wide, it will cut off top and bottom to prevent stretching as the screen gets even smaller, it cuts off the sides instead to prevent stretching. when this happens depends on the aspect ratio of the image. If you don't want it to cut off anything, you can set 100% auto instead of cover. This means the width will be 100% and the height will be undefined but you shouldn't set width:100%; on a div, div are block elements, block elements takes full width by default, setting width:100%; on a div is only going to cause overflow issues
Tok124 (CSS Nerd)
Tok124 (CSS Nerd)ā€¢6d ago
Kevin Powell
YouTube
CSS width auto vs 100% | What's the difference?
A look at the difference between width: auto and width: 100% #css -- Come hang out with other dev's in my Discord Community šŸ’¬ https://discord.gg/nTYCvrK --- Keep up to date with everything I'm up to āœ‰ https://www.kevinpowell.co/newsletter --- Help support my channel šŸ‘Øā€šŸŽ“ Get a course: https://www.kevinpowell.co/...
roger
rogerOPā€¢6d ago
It does not work this way somethings wrong I need to define the height in that case Defining height is creating a lot of white space and making text up and down
clevermissfox
clevermissfoxā€¢6d ago
Aspect ratio may be a better property then height
Tok124 (CSS Nerd)
Tok124 (CSS Nerd)ā€¢6d ago
Yeah, i agree with clevermissfox, if you set an expect ratio of the div, the height will be adjusted automatically based on the width. You can check the aspect ratio of the image itself in the devtools. So you can set aspect-ratio:512/207; on the div
No description
Tok124 (CSS Nerd)
Tok124 (CSS Nerd)ā€¢6d ago
.award-gutter {
.full-bg {
background: url("https://s3-alpha-sig.figma.com/img/1465/19a9/915b85a431b3cd2126bcaaee8871f565?Expires=1743984000&Key-Pair-Id=APKAQ4GOSFWCW27IBOMQ&Signature=rK6QYGL~KM75Cu8rsRz7ss1mD2umSimyrmeT2A5udxYAqgQh~sLUk~dpovX5GbY2o0x4y3ygx5OSGkMPSZQdHfQLhYFQoCwgzFzStuwgp4N8M6GF-IhrT7-xULvt-cXzlcRy4EUbBGYskiDugIIxzCqt4MKiC-qpLgLAQSDmVqLF2KjNXz0Sih8wMSFM9hhIsoiYq-d-vAzsb6RflXqEwqb-PLqbLnBJsD-KoLlyvIUUjq5zTPIXs3pF5-SDn1lxKskKWZJw-lvbN2cxzahmDGzS2RiFXlfwi1JcVBbFVVrpB5h7CUIDwEYBDi5A3hOBiNBxkHky5L6cE2YGNv5AeQ__")
no-repeat center / cover;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
aspect-ratio: 512/207;
}
}
.award-gutter {
.full-bg {
background: url("https://s3-alpha-sig.figma.com/img/1465/19a9/915b85a431b3cd2126bcaaee8871f565?Expires=1743984000&Key-Pair-Id=APKAQ4GOSFWCW27IBOMQ&Signature=rK6QYGL~KM75Cu8rsRz7ss1mD2umSimyrmeT2A5udxYAqgQh~sLUk~dpovX5GbY2o0x4y3ygx5OSGkMPSZQdHfQLhYFQoCwgzFzStuwgp4N8M6GF-IhrT7-xULvt-cXzlcRy4EUbBGYskiDugIIxzCqt4MKiC-qpLgLAQSDmVqLF2KjNXz0Sih8wMSFM9hhIsoiYq-d-vAzsb6RflXqEwqb-PLqbLnBJsD-KoLlyvIUUjq5zTPIXs3pF5-SDn1lxKskKWZJw-lvbN2cxzahmDGzS2RiFXlfwi1JcVBbFVVrpB5h7CUIDwEYBDi5A3hOBiNBxkHky5L6cE2YGNv5AeQ__")
no-repeat center / cover;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
aspect-ratio: 512/207;
}
}

Did you find this page helpful?