Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get 2 images inside flexbox items to full screen width

1 image is full-width

I cannot get both images to be the same width with a relative position.
Both images are placed inside a flexbox container, and then placed in another div, item 1 and item 2 respectively.

This is my HTML code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<!-- parliament background -->
<div class="container">
  <div class="item1">
    <img
      class="img3"
      src="pictures/1920px-Parliament_of_Hungary_November_2017.jpg"
      alt=""
      style="width: 100%"
    />
  </div>
  <!-- parliament end -->
  <!-- mountain background -->
  <div class="item2">
    <img
      class="img4"
      src="pictures/output-onlinepngtools.png"
      alt=""
      style="width: 100%"
    />
  </div>
  <!-- mountain end -->
</div>

This is my CSS code:

/* parliament photo */
.img3 {
  width: 100%;
  height: auto;
  opacity: 20%;
}

/* mountain photo */
.img4 {
  height: auto;
  width: 100%;
}

.container {
  position: absolute;
  display: flex;
  flex-wrap: wrap;
}

>Solution :

.img3 {
  width: 100%;
  height: auto;
  opacity: 20%;
}

/* mountain photo */
.img4 {
  height: auto;
  width: 100%;
}

.container {
  width:100vw;
  position: absolute;
  display: flex;
  flex-wrap: wrap;
  border:1px solid red;
}

.item1{
  width:100vw;
   
}
.item2{
  width:100vw;

}
<!-- parliament background -->
<div class="container">
  <div class="item1">
    <img
      class="img3"
      src="https://cdn.pixabay.com/photo/2023/03/05/14/00/motion-7831456_960_720.jpg"
      alt=""
      
    />
  </div>
  <!-- parliament end -->
  <!-- mountain background -->
  <div class="item2">
    <img
      class="img4"
      src="https://media.istockphoto.com/id/852010454/photo/motion-speed-light-tail-with-night-city-background.webp?s=612x612&w=is&k=20&c=ad5gYPia7h80wQ_tNqdvYdyUbcbLwDWcNikhn9zYW0o="
      alt=""
      
    />
  </div>
  <!-- mountain end -->
</div>

css


.img3 {
  width: 100%;
  height: auto;
  opacity: 20%;
}

/* mountain photo */
.img4 {
  height: auto;
  width: 100%;
}

.container {
  width:100vw;
  position: absolute;
  display: flex;
  flex-wrap: wrap;
}

.item1{
  width:100vw;

}
.item2{
  width:100vw;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading