我正在构建一个网格,在该网格中,我将拥有覆盖特定单元格的多行"单元格"和项目.

The goal is to emulate this enter image description here

它由一个父div(整个网格)和多个单元格(浅蓝色)组成.然后,卡片(黄色)是特定单元格的子级,位置:绝对,并覆盖在顶部.

这使得堆叠上下文能够在所有单元中保持相同,因为它们都是同一父单元的一部分.


我想做的是在它们自己的父行div中设置每一行单元格(一张卡片位于一行).

问题是黄牌的框影在这种格式下不能正确显示.

.container {
  width: 100px;
  height: 50px;
  position: relative;
}

.one {
  position: absolute;
  top: 0;
  border: 1px solid black;
  height: 100%;
  width: 70px;
  box-shadow: 5px 5px blue;
  background-color: lightyellow;
  
}
.two {
  background-color: coral;
  height: 100%;
  position: absolute;
  top: 0px;
  border: 1px solid grey;
}
.three {
  border: 1px solid green;
  width: 100%;
  height: 100%;
  background-color: lightblue;
}
<div class='container'>
  <div class='one'>
    One
  </div>
  <div class='three'>

  </div>
</div>

<div class='container'>
  <div class='two'>
    Two
  </div>
  <div class='three'>
   
  </div>
</div>

长方体阴影不在下面的一行中.

enter image description here

我理解这与堆叠上下文有关. 但这真的能按照我想要的方式来做吗?

推荐答案

只要让第.one和第.two类与第z-index类相同并大于第.three类就行了‘S

.container {
  width: 100px;
  height: 50px;
  position: relative;    }

.one {
  position: absolute;
  top: 0;
  border: 1px solid black;
  height: 100%;
  width: 70px;
  box-shadow: 5px 5px blue;
  background-color: lightyellow;
  z-index: 10;
  
}
.two {
  background-color: coral;
  height: 100%;
  position: absolute;
  top: 0px;
  border: 1px solid grey;
  z-index: 10;
}
.three {
  border: 1px solid green;
  width: 100%;
  height: 100%;
  background-color: lightblue;
  z-index: 5;
}
<div class='container'>
  <div class='one'>
    One
  </div>
  <div class='three'>

  </div>
</div>

<div class='container'>
  <div class='two'>
    Two
  </div>
  <div class='three'>
   
  </div>
</div>

Html相关问答推荐

一次悬停可触发同一分区中的另一次悬停

如何格式化HTML文本,使其环绕关键字

如何删除在小屏幕上单击按钮时出现的蓝色方块?

如何在用css使用网格视图时设置宽度?

如何创建剪切到路径的循环文本字幕?

浏览器是否可以呈现存储在代码点0x09处的字形?

如何使VS代码支持以模仿嵌套的方式对已经包含注释的HTML进行注释?

我如何确保我的网格永远不会小于它的子网格

如果最后一行的卡数少于其他行,则在使用flex grow使卡在调整大小时拉伸后,flex卡的宽度将被拉伸

顶部有文字的图像的悬停效果

UL 的行为就像它不属于任何类别

即使必填字段为空,HTML 表单也已成功提交

使用图像自定义 CSS 网格边框

为什么在使用src与srcdoc时 iframe 内容高度呈现不同?

如何让 Reindeer 居中

使用 Selenium for Python 在网站上查找类名称中包含换行符的元素

调整大小时 CSS 溢出

为什么相同持续时间的转换需要不同的时间?

focusout() Select 器不适用于搜索框

无法使用 Reactjs 多次更新本地存储