• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS why the background of qty-class element doesnt appear in front of image?

Immortality

New Coder
Where is the problem? I couldn't figure it out.
Code:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      img {
        width: 180px;
        height: 260px;
      }
      .box-container {
        width: 180px;
        height: 260px;
        margin-right: 12px;
        position: relative;
      }
      .box-container > .inner-box {
        position: absolute;
        width: 180px;
        height: 260px;
        top: 0;
        left: 0;
        font-family: Robos;
        font-weight: 700;
        font-size: 25px;
        color: #ffd700;
        background-color: #111;
        opacity: 0;
        transition-duration: 0.5s;
        text-align: center;
        transform: translateY(260px);
        padding-top: 60%;
        text-decoration: none;
      }
      span {
        padding-bottom: 15px;
      }
      i {
        font-size: 25px;
      }
      a:link {
        color: #ffd700;
      }
      .box-container:hover .inner-box {
        opacity: 0.9;
        transform: translateY(0);
      }
      .qty {
        display: block;
        margin-top: -263px;
        margin-right: 10px;
        font-size: 10px;
        height: 30px;
        background-color: #222;
        color: purple;
      }
    </style>
  </head>
  <body>
    <div class="box-container">
      <img
        src="image/1.jpg" alt="test"
      />
      <span class="qty">WEB-DL</span>
      <div class="inner-box">
        <span>WEB-DL</span> <br />
        <a href="#">7.6 <i class="fab fa-imdb"></i></a>
      </div>
    </div>
  </body>
</html>
 

Johna

Frontend Web Developer
Staff Team
Guardian
Oh I thought you meant you have an element with an image inside it, and then you want the background of that element in front of the image. If you get what I mean?

Anyway, try increasing the z-index of the qty class, or try making it a div instead of a span. Maybe it's something to do with span being an inline element?
 
Top