I've been working on optimizing my mobile website using a responsive column layout. The challenge I'm facing is getting the images within each column to stretch to 100% width while automatically adjusting their height.
I experimented with setting max-width:100% and max-height:100%, but unfortunately, this didn't achieve the desired result of filling the image width to 100% of the column's area. While it did resize the column height to fit the image, the image itself wouldn't adjust to meet the 100% width requirement.
Here's the snippet of my code:
<div class="container">
<div class="column" id="column1">
<img id="top_block_graphic" src="graphics/top-block.png" alt=""/>
</div>
</div>
CSS:
.container {
display: grid;
grid-template-columns: 50% 50%;
grid-gap: 7px;
clear: both;
padding: 10px;
font-size: 1.6em;
width: 100%;
}
.column {
background-color: rgba(173,167,133,0.5);
padding: 10px;
border: 1px solid black;
}
#column1 {
grid-column: 1/3;
width: 100%;
height: auto;
position: relative;
overflow: hidden;
padding: 35.66% 0 0 0;
}
#top_block_graphic {
display: block;
max-width: 100%;
height: auto;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}