Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS

Mark Libario
Mark Libario
9,003 Points

Help with overlapping images..

Hey guys..

I want two same images to overlap each other like 2 tiles a little bit spread apart (bottom,right)

I tied z-index and positionings but the two image just displays as block level.. Heres the CSS

.protein1 {
  position: relative;
  margin-left: auto;
  margin-right: auto;
  top: 0;
  left: 0;
  z-index: 1;
}

.protein2 {
  position: absolute;
  margin-left: auto;
  margin-right: auto;
  top: 250px;
  left: 350px;
  z-index: -1;
}

Heres the HTML:

     <div class="container">
     <div class="protein1">
       <img src="img/protein1.jpg" width= 400px height= 550px class="rounded img-fluid">

       </div>

      <div class="protein2">
       <img src="img/protein1.jpg" width= 400px height= 550px class="rounded img-fluid">

       </div>
      </div>

I changed the image size directly because its too big, is there anyway I can change it ?

The style I wanted to do was that these two overlapping images are floated on the right side while the "text descriptions" are wrapping around it from the left.

1 Answer

Your images are probably displaying as block level because they are wrapped in divs. Divs are block level elements, and images are inline elements. If you can, I'd suggest taking away the wrapper divs around your images so that they can be inline with one another, and therefore overlap.

If you can't remove the divs for some reason, try adding display: inline to their styles and see if that helps.