|
|
|
|
|
by hot_gril
727 days ago
|
|
Either ChatGPT has gotten better or I gave it a better prompt this time. It suggested this padding-bottom hack that sorta works but requires hardcoding aspect ratios, which I didn't want, but at least it demonstrates the layout we wanted with a Windows XP Bliss background image example: <style>
.image-container {
position: relative;
width: 100%;
height: 0;
padding-bottom: 80.44%; /* h/w aspect ratio */
background-image: url('https://d7hftxdivxxvm.cloudfront.net/?quality=80&resize_to=width&src=https%3A%2F%2Fartsy-media-uploads.s3.amazonaws.com%2F2RNK1P0BYVrSCZEy_Sd1Ew%252F3417757448_4a6bdf36ce_o.jpg&width=910');
background-size: cover;
background-position: center;
}
</style>
<div class="image-container">hi</div>
<div class="image-container">hi2</div>
<div class="image-container">hi3</div>
Though it seems laggier than the React version when I resize, and this doesn't get into making the text resize to fit the divs... |
|
What you have is basically just an image element with width: 100 height: auto, but it has children.
Here's an example, written with tailwind for my convenience but should be pretty legible to anyone who knows CSS:
The height of the container is governed by the height of the image (until the text becomes taller than the image). You still have fully fleixible in terms placement (place-self) and/or sizing (height: 100%) of the text container.