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

Image overflowing outside a div

I have a container with the left side and right side. i have an image on the right side and it is overflowing hence the experience is bad.

I tried putting overflow: hidden but it is still going outside the box. I want the Right side to have a max-width of 50vw and anything that goes past it should be hidden.

What am I doing wrong?

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

.halfcontainer {
  display: flex;
  flex-direction: column;
  height: 100vh;
  align-items: center;
  justify-content: center;
  margin: 20px;
 }
 
 
  .righthalf{
    overflow: hidden;
   max-width:50vw;
  }
  
    .hero__image {
    display: block;
    position: absolute;
    width: 70%;
    top:10%;
    right: -30%;
    overflow: hidden;
  }
  <section >
        <div   class="halfcontainer">
        <div class="lefthalf">
            <h1>Hello world</h1>
        </div>
        <div class="righthalf">
          <img class="hero__image" src="images/hero.webp" />
        </div>
    </div>
            </section>

>Solution :

Just add Overflow hidden to parent div .halfcontainer

.halfcontainer {
  display: flex;
  flex-direction: column;
  height: 100vh;
  align-items: center;
  justify-content: center;
  margin: 20px;
  position:relative;
  overflow-x:hidden;
 }
 
 
  .righthalf{
    overflow: hidden;
   max-width:50vw;
  }
  
    .hero__image {
    display: block;
    position: absolute;
    width: 70%;
    top:10%;
    right: -30%;
    overflow: hidden;
  }
<section >
  <div   class="halfcontainer">
  <div class="lefthalf">
      <h1>Hello world</h1>
  </div>
  <div class="righthalf">
    <img class="hero__image" src="
https://picsum.photos/seed/picsum/200/300" />
  </div>
</div>
      </section>
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