首页 > 解决方案 > 特定宽度的内容左侧和右侧的水平线

问题描述

我有一个标题,我想在这个标题的左侧和右侧放置一条水平虚线,正如您在 jsfiddle 中看到的那样

https://jsfiddle.net/uLake5g3/9/

这是我的 HTML:

<div class = "spotlight">
  <div class = "container spotlight__main">
    <h2><span class  ="background__red">In the spotlight</span></h2>
  </div>
</div>

这是我的 CSS:

h2 > span {
  position: relative;
  display: inline-block;
}

h2 > span:before,
h2 > span:after {
  content: "";
  position: absolute;
  top: 50%;
  border-bottom: 1px dashed;
  width: 96rem;
  margin: 0 auto;
  vertical-align: center;
}

h2 > span:before {
  right: 100%;
}

h2 > span:after {
  left: 100%;
}

我想在spotlight_main 他的边界内有虚线,但它们在外面。

标签: htmlcssborder

解决方案


你可以试试:

h2:before{
    border-bottom: 1px dashed;
    color: #fff;
    content: "";
    left:0;
    position: absolute;
    right:0;
    top: 50%;
}

推荐阅读