I am trying to place the child flexboxes in my parent flexbox to be in one row, vertically and horizontally centered, and have space between them with gap property in css but the images and embedded video inside those child flexbox don’t seem to horizontally stretch.
.latest-news-format {
background-color: #8ebfa1;
display: flex;
justify-content: space-around;
align-items: stretch;
gap: 10px;
}
.latest-news-format div {
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
max-height: 100%;
border: 1px solid black;
}
.latest-news-format div img {
/* max-width: 100%; */
object-fit: cover;
max-height: 80%;
max-width: 100%;
/* aspect-ratio: 16/9; */
}
.latest-news-format div p {
text-align: center;
/* This centers the text within each div */
margin-bottom: auto;
/* This pushes the text to the bottom of the div */
}
.latest-news-format div iframe {
/* object-fit: cover; */
flex-grow: 1;
flex-shrink: 1;
aspect-ratio: auto;
margin: auto;
}
<div style="max-width: 100%; height: 20%; background-color: bisque; display:flex; flex-wrap: wrap; align-content: space-evenly; margin: 20px 0px;">
<h2>
Latest News
</h2>
<br>
<div style="margin: 15px 15px;" class="latest-news-format">
<!--iKON news-->
<div>
<a href="https://www.soompi.com/article/1598908wpp/ikons-jinhwan-announces-military-enlistment-date-with-heartfelt-message" title="iKON Jinhwan Enlistment Announcement" target="_blank">
<img style="object-fit: contain; max-width: 100%;" src="https://picsum.photos/200/300.webp" alt="iKON group photo">
<p>
iKON Jinhwan Enlistment Announcement with Heartfelt Letter
</p>
</a>
</div>
<!--SEVENTEEN news-->
<div>
<a href="https://www.soompi.com/article/1648474wpp/seventeen-to-headline-lollapalooza-berlin-2024" title="SEVENTEEN Headline at Lollapalooza 2024" target="_blank">
<img src="https://picsum.photos/200/300.webp" alt="SEVENTEEN group photo">
<p>SEVENTEEN Perform At Lollapalooza Berlin</p>
</a>
</div>
<!--SEVENTEEN watch-->
<div>
<iframe src="https://youtu.be/4g6AC6mXShE?si=bxoYJBNyIaxXMNCp"></iframe>
<a href="https://youtu.be/4g6AC6mXShE?si=bxoYJBNyIaxXMNCp" title="Going SEVENTEEN EP.79" target="_blank">
<p>
Watch: Going SEVENTEEN New Episode 79 - Going Vol 2
</p>
</a>
</div>
<!--TAEYONG news-->
<div>
<a href="https://www.soompi.com/article/1649391wpp/ncts-taeyong-confirms-military-enlistment-date" title="Taeyong Enlistment Date" target="_blank">
<img src="https://picsum.photos/200/300.webp" alt="Taeyong picture" title="Taeyong Enlistment Date">
<p>
SM Confirms Taeyong Military Enlistment Date
</p>
</a>
</div>
</div>
</div>
expect to see all img/iframe (embedded video) to have equal width, fully horizontally stretched within its flexbox, equal height. there must be a gap between child flexbox
2
Answers
Make below changes in your css:
This is a place where CSS grid would be better than flexbox. It will make it easier for you to ensure that each item in the grid is the same size and will make it much easier for you to create a responsive design.
Responsive Example: