I want to have these three images in a grid with equal width inside thier container with 50% width of the screen as this:
.three-image-container {
display: grid;
grid-template-columns: auto auto auto;
grid-gap: 10px;
width 50%;
}
.img-frame-container {
border: 5px solid #e8e8e8;
border-image: linear-gradient(#a8acb180, #aeb1b682);
box-shadow: 1px 7px 20px 9px rgb(0 0 0 / 75%);
border-radius: 5px;
cursor: pointer;
background: #dfe4ea;
user-select: none;
width: 100%;
height: 100px;
max-width: 100%;
box-sizing: border-box;
object-fit: cover;
transition: all 0.2s ease;
}
.img-frame {
width: 100%;
height: 100%;
object-fit: cover;
}
<div class="three-image-container">
<div class="img-frame-container green-frame">
<img class="img-frame" src="https://images.unsplash.com/photo-1488161628813-04466f872be2?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=464&q=80">
</div>
<div class="img-frame-container red-frame">
<img class="img-frame" src="https://images.unsplash.com/photo-1539571696357-5a69c17a67c6?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80">
</div>
<div class="img-frame-container red-frame">
<img class="img-frame" src="https://images.unsplash.com/photo-1583195764036-6dc248ac07d9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1176&q=80">
</div>
</div>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
How can I have these three with equal width and fixed 100px height.
Note: each picture should cover all of the frame as others no matter what aspect ratio it has...
CodePudding user response:
Try this
.three-image-container {
display: grid;
grid-template-columns: 33% 33% 33%;
grid-gap: 10px;
width 50%;
}
.img-frame-container {
border: 5px solid #e8e8e8;
border-image: linear-gradient(#a8acb180, #aeb1b682);
box-shadow: 1px 7px 20px 9px rgb(0 0 0 / 75%);
border-radius: 5px;
cursor: pointer;
background: #dfe4ea;
user-select: none;
width: 100%;
height: 100px;
max-width: 100%;
box-sizing: border-box;
object-fit: cover;
transition: all 0.2s ease;
}
.img-frame {
width: 100%;
height: 100%;
object-fit: cover;
}
<div class="three-image-container">
<div class="img-frame-container green-frame">
<img class="img-frame" src="https://images.unsplash.com/photo-1488161628813-04466f872be2?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=464&q=80">
</div>
<div class="img-frame-container red-frame">
<img class="img-frame" src="https://images.unsplash.com/photo-1539571696357-5a69c17a67c6?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80">
</div>
<div class="img-frame-container red-frame">
<img class="img-frame" src="https://images.unsplash.com/photo-1583195764036-6dc248ac07d9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1176&q=80">
</div>
</div>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CodePudding user response:
A couple of points:
As was pointed out in a comment your containing div actually did not have width of 50% as it was missing a colon.
If you want the 3 images to have the same width within the grid then you can tell the grid that not with auto (which will take into account the natural dimensions of the images) but with fr setting.
Given that you are already setting the image to 'cover' then regardless of their natural aspect ratios the system will make sure each covers its grid area - cropping top and bottom or at the sides as necessary.
.three-image-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 10px;
width: 50%;
}
.img-frame-container {
border: 5px solid #e8e8e8;
border-image: linear-gradient(#a8acb180, #aeb1b682);
box-shadow: 1px 7px 20px 9px rgb(0 0 0 / 75%);
border-radius: 5px;
cursor: pointer;
background: #dfe4ea;
user-select: none;
width: 100%;
height: 100px;
max-width: 100%;
box-sizing: border-box;
object-fit: cover;
transition: all 0.2s ease;
}
.img-frame {
width: 100%;
height: 100%;
object-fit: cover;
}
<div class="three-image-container">
<div class="img-frame-container green-frame">
<img class="img-frame" src="https://images.unsplash.com/photo-1488161628813-04466f872be2?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=464&q=80">
</div>
<div class="img-frame-container red-frame">
<img class="img-frame" src="https://images.unsplash.com/photo-1539571696357-5a69c17a67c6?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80">
</div>
<div class="img-frame-container red-frame">
<img class="img-frame" src="https://images.unsplash.com/photo-1583195764036-6dc248ac07d9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1176&q=80">
</div>
</div>
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>