Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

overlay for div or image to show text not working with pseudo element

$
0
0

I want to show transparent background overlay between image & text so that text is readable.

I tried in the below code for some reason its not working for container or image

.container {
  max-width:1000px;
  position: relative;
  text-align: center;
  color: white;
}

.bottom-left {
  position: absolute;
  bottom: 8px;
  left: 16px;
}

.top-left {
  position: absolute;
  top: 8px;
  left: 16px;
}

.top-right {
  position: absolute;
  top: 8px;
  right: 16px;
}

.bottom-right {
  position: absolute;
  bottom: 8px;
  right: 16px;
}

.centered {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.container > img::before{position:absolute; background-color:red; width:100%; height:100px;}

/*.container ::before{position:absolute; background-color:red; width:100%; height:100px;}

.container::before{position:absolute; background-color:red; width:100%; height:100px;}*/
<div class="container"><img src="https://www.w3schools.com/howto/img_snow_wide.jpg" alt="Snow" style="width:100%;"><div class="bottom-left">Bottom Left</div><div class="top-left">Top Left</div><div class="top-right">Top Right</div><div class="bottom-right">Bottom Right</div><div class="centered">Centered</div></div>

Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>