html - 如何在标题上绘制双底边框?

标签 html css css-shapes

我怎样才能做如下图所示的事情?

enter image description here

我想在我所有的 h1 上加一条粗线,但不太确定这样做的最佳做法。

HTML:

<h1>This is Our Work</h1>

CSS:

h1{
  border-bottom: 1px solid #246cb4;
  display: inline-block;
}

h1:after {
  content: "";
  display: block;
  border: 1px solid black;
  width: 50px;
  margin-top: 0px;
  position: absolute;
}

Codepen :

最佳答案

在这种情况下你不需要任何伪元素。

您可以使用 css3 绘制多个背景图像 linear-gradient()具有精确控制的尺寸和位置:

h1 {
  background-image: linear-gradient(to right, #246cb4, #246cb4),
                    linear-gradient(to right, #246cb4, #246cb4);

  background-repeat: no-repeat;
  background-size: 100% 1px, 50px 3px;
  background-position: bottom 2px left, bottom 1px center;
}

h1{
  background-image: linear-gradient(to right, #246cb4, #246cb4),
    linear-gradient(to right, #246cb4, #246cb4);

  background-size: 100% 1px, 50px 3px;
  background-repeat: no-repeat;
  background-position: bottom 2px left, bottom 1px center;

  position: relative;
  display: inline-block;
}
<h1>This is Our Work</h1>

关于html - 如何在标题上绘制双底边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41672178/

相关文章:

javascript - 在没有链接的情况下将大部分 CSS 和 JS 嵌入 <head>

javascript - 文本框的客户端验证

jquery - 如何使用 jQuery 实现这种轮播效果(挑战……好吧,对我来说)

html - 元素不会居中,尤其是在调整屏幕大小时

javascript - 为什么我网站上的 JavaScript 只有在我刷新页面后才能工作?

html - 如何阻止 prettier 格式化 HTML 文件?

javascript - 悬停时在图像上显示链接

css - 如何将 EMAIL 上的图像变暗?

html - 如何将箭头添加到div?

html - CSS三 Angular 形以适应可变大小的div元素