提问者:小点点

将图像浮动到另一个问题css


我正在使用相对绝对位置,但它不起作用。 我错在哪里?

我的HTML代码:

null

.slide-item {
  text-align: center;
  height: 400px;
  position: relative;
}

.slide-item img {
  display: block;
}

.slide-item .sale {
  position: absolute;
  top: -20px;
  right: 20px;
  display: block;
}
<div class="slide-item">
  <div class="sale">
    <img src="https://via.placeholder.com/50" alt="">
  </div>
  <img src="https://via.placeholder.com/150" class="arr-img" alt="">
</div>

null


共1个答案

匿名用户

请尝试此代码。。。

<!DOCTYPE html>
<html>
<head>
    <style>
        .slide-item {
            text-align: center;
            height: 400px;
            position: relative;
        }

        .slide-item img:nth-child(2){
            position: relative;
            width: 1150px;
            height: 600px;
            left: 65px;
            top: 25px;
        }

        .slide-item img {
            display: block;
        }

        .slide-item .sale img {
            position: absolute;
            top: 0px;
            right: 150px;
            z-index: 1;
        }
    </style>
</head>
    <body>
    <div class="slide-item">
        <div class="sale">
            <img src="img/icons8-round-128.png" alt="">
        </div>
        <img src="img/111713927-green-screen-green-background-green-screen-stock-footage-video.jpg" class="arr-img" alt="">
    </div>
    </body>
</html>