可以,可以使用CSS的position属性。将父级div设置为position:relative,将子级div设置为position:absolute,并且top和left值为0,子级div就会被压在父级div下面。具体代码如下:

HTML:

<div class="parent">
  <div class="child">
    我被压在父级div下面了
  </div>
</div>

CSS:

.parent {
  position: relative;
  width: 200px;
  height: 200px;
  background-color: #eee;
}

.child {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #ccc;
  z-index: -1;
}

在这个示例中,子级div的z-index值为-1,比父级div的z-index值低,因此子级div会被父级div覆盖,看起来就像是被压在下面了。

可以让一个div被压在父级div下面嘛

原文地址: https://www.cveoy.top/t/topic/bX9D 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录