-1

I want my text to appear over an image, at the bottom of the image. I can get it to work but when I scale the page, the text moves out of the div (below the image). I want it to stay in the same place when i scale the page.

HTML

<div class="header">
  <img src="images/ct.jpg" class="info-image">
  <p class="HeaderText">Canterbury Tales<p>
</div>

CSS

.info-image {
width:100%;
position:relative;
}

.HeaderText {
position:absolute;
left:35px;
bottom: 10px;
font-size: 3em;
}

website: explorecanterbury.co.uk

the div can be found by clicking on canterbury tales building

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
user2953989
  • 2,791
  • 10
  • 36
  • 49
  • Your main issue is that the `.HeaderText` is absolute relative to `.header` and not `.info-image`. all you have to do is give `position:relative;` to `.header`, and `position:absolute;` to `.info-image` & `.HeaderText` – dcohenb Mar 17 '16 at 12:57

2 Answers2

0

You have a few problems:

  • You need to close <p> with </p>.
  • Use position: relative on the .header.

Like this?

.header {
  position: relative;
  width: 500px;
}
.info-image {
  max-width: 100%;
  position: relative;
  display: block;
}
.HeaderText {
  position: absolute;
  top: 50%;
  text-align: center;
  left: 0;
  right: 0;
  transform: translate(0, -50%);
  font-size: 3em;
  margin: 0;
  padding: 0;
}
<div class="header">
  <img src="//placehold.it/500" class="info-image">
  <p class="HeaderText">Canterbury Tales</p>
</div>

Preview

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
-2

Give the image a lower z-index then the text:

.info-image {
width:100%;
position:relative;
z-index: 1;
}

.HeaderText {
position:absolute;
left:35px;
bottom: 10px;
font-size: 3em;
z-index:2;
}

If that doesn't work, try giving the image a position of absolute, and the text a position of relative.

Maarten Wolfsen
  • 1,625
  • 3
  • 19
  • 35
  • The p tag has a higher z-index by default because it's later in the DOM, z-index has nothing to do with this. – dcohenb Mar 17 '16 at 12:56