html - 用一些像素从左右插入边框底部

标签 html css border

我想知道,是否可以给 border-bottom 一个类似 padding-leftpadding-right 的东西>。我有两个 div,它们有一些边框。我想让顶部 div 的 border-bottom 在左右两侧有一些 padding。我不知道这是否可能。我知道结构很奇怪(我可以轻松地使用整个盒子包装器周围的边框,而不是使用 border-bottom 来实现这一点)。问题是,我使用的插件具有这样的结构,我必须像这样自定义它,因为正是这种结构和样式。希望它足够清楚。这里有一张图片应该是什么样子和一个示例片段:

enter image description here

.box {
  display: flex;
  flex-direction: column;
  width: 200px;
}

.box__top {
  border: 1px solid black;
  border-bottom: 1px solid red;
  height: 20px;
  padding: 10px;
  text-align: center;
}

.box__bottom {
  border: 1px solid black;
  border-top: none;
  height: 150px;
  padding: 10px;
  text-align: center;
}
<div class="box">
  <div class="box__top">
    <span>I'm the top section</span>
  </div>
  <div class="box__bottom">
    <span>I'm the top section</span>
  </div>
</div>

最佳答案

改用伪元素:

.box {
  display: flex;
  flex-direction: column;
  width: 200px;
}

.box__top {
  border: 1px solid black;
  border-bottom: none;
  position: relative;
  height: 20px;
  padding: 10px;
  text-align: center;
}

.box__top::after {
  content: " ";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 90%;
  height: 1px;
  background-color: red;
}

.box__bottom {
  border: 1px solid black;
  border-top: none;
  height: 150px;
  padding: 10px;
  text-align: center;
}
<div class="box">
  <div class="box__top">
    <span>I'm the top section</span>
  </div>
  <div class="box__bottom">
    <span>I'm the top section</span>
  </div>
</div>

关于html - 用一些像素从左右插入边框底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48708206/

相关文章:

javascript - 使用此 javascript 在屏幕中央打开新窗口?

javascript - 如何在 Ionic css 上添加带状标签

javascript - Pinterest 下拉菜单的工作原理是什么?

html - 将图像包装到 div 中但保持纵横比

html - 如何在表格中的输入 td 上创建边框?

android - 在 Android 中为图像添加框架或边框

php - 更新div中的数据

html - 使用 CSS : background-image not displaying 进行视差滚动

css - :before and :after pseudo elements on html tag is wonky in Chrome

html - 父 div 的边框不绑定(bind)到子元素的大小