css - 显示覆盖另一个 div 的 div 边框

标签 css border

我已经尝试了此处显示的方法,但没有成功:

StackOverflow: Display div border on top of another div [duplicate] (my own postage)

我有 2 个嵌套的 div,上面的方法对两个 div 都不起作用。

代码如下:

html:

<div className="App">
        <div class="box mainClass1" id="1">
          <div class="helperClass" />
        </div>
        <div class="box mainClass2" id="2">
          <div class="helperClass" />
        </div>
</div>

CSS:

.box {
  width: 100px;
  height: 100px;
  position: absolute;
}

.mainClass1 {
  top: 100px;
  left: 100px;
  background: teal;
}
.mainClass2 {
  top: 150px;
  left: 150px;
  background: red;
}

.helperClass2 .helperClass {
  width: 100%;
  height: 100%;
  border: 3px solid #4286f4;
  box-sizing: border-box;
}

注意:helperClass2 应该添加到父(外部)div 的类列表中。

最佳答案

.container {
  position: relative;
}
.box1 {
 width: 100px;
 height: 100px;
 position: absolute;
 top: 100px;
 left: 100px;
 box-sizing: border-box;
 background: blue;
}

.box1:after {
  content: '';
  display: block;
  width: 95px;
 height: 95px;
 position: absolute;
 border: 3px solid black;
 z-index: 3;

}

.box2 {
 width: 100px;
 height: 100px;
 position: absolute;
 top: 150px;
 left: 150px;
 box-sizing: border-box;
 background: red;
 border: 3px solid black;
}
<div class="container">
  <div class="box1"></div>
  <div class="box2"></div>
</div>

关于css - 显示覆盖另一个 div 的 div 边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59822881/

相关文章:

html - 无法摆脱 HTML 表格边框 - 使用屏幕截图和 jfFiddle

uitextview - 设置 UITextView ios 的边框

html - 可变宽度容器中的截断文本

html - Twitter Bootstrap 的底部填充/边距问题

html - 宽度 : 50% mean when the container is body? 是什么意思

android - 如何在不使用android中的图像的情况下增加复选框边框

C# WPF带边框的透明窗口

python - 在我的代码中添加边框和图像

css - IE9 最初无法识别带有 SVG 背景图像的伪元素的高度

javascript - React 在嵌套的 <a></a> 中不显示 css 样式