0

I am trying to overlay two images in HTML code over text that is displayed on my webpage in CSS, what is the simplest way to accomplish this. I want these two images on top of the text that is currently on top of these images.

HTML Code:

<body>
            <img src="" id="image" style="width:270px;height:270px; position:absolute; left:2270px;top:770px;"/>
            <img src="" id="image1" style="width:270px;height:270px; position:absolute; left:30px;top:770px;"/>
    </body>
StackGuru
  • 133
  • 7

2 Answers2

2

Use z-index, position: relative; and position: absolute;.
Here is your HTML:

<body>
   <img src="" id="image" style="width:270px;height:270px;"/>
   <img src="" id="image1" style="width:270px;height:270px;"/>
   This is a text!
</body>

Then add CSS:

img {
   position: relative;
   z-index: 1;
}

div {
  position: absolute;
  top: 0px; //To see the difference
}

CodePen: https://codepen.io/marchmello/pen/ExjqGYQ

MARSHMALLOW
  • 1,315
  • 2
  • 12
  • 24
2

You should use z-index for overlaying text and images:

img {
  position: absolute;
  z-index: 2;
  width: 200px;
}

div {
  position: relative;
  z-index: 1;
  color: black;
}
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg" />
<div>This is text over the image that goes on for a while</div>
Jack
  • 1,893
  • 1
  • 11
  • 28