html - 使标题下划线时尚的不同方法是什么?

标签 html css

我想做与下面相同的事情,但使用 CSS 的方式不同。

Slanted underline using CSS

.container {
  width: 100%;
  padding: 50px;
  display: block;
}

h2 {
  font-size: 35px;
  line-height: 1.2;
  margin: 0;
  width: 500px;
}

.heading-border {
  position: relative;
  background: url('https://i.ibb.co/PM2s0mj/green-shape.png');
  background-size: 100% 8px;
  background-position: bottom;
  background-repeat: no-repeat;
}

.heading-border:before {
  content: ' ';
  background: #fff;
  height: 13px;
  width: 12px;
  display: inline-block;
  margin: 0px 0px -8px -6px;
  transform: rotate(-45deg);
}

.heading-border:after {
  content: ' ';
  background: #fff;
  height: 13px;
  width: 12px;
  display: inline-block;
  margin: 0px -6px -17px 0;
  transform: rotate(-45deg);
}
<div class="container">
  <h2>This is heading <span class='heading-border'>this is stylish heading line</span></h2>
</div>

当我使用背景颜色时会发生这种情况 http://prntscr.com/ny8uog

我想要的东西与我在上面的代码中提到的相同,但方式不同,所以如果我将在标题后面使用背景色,那么补丁应该不可见。

最佳答案

使用像下面这样的背景,你可以很容易地控制线条的 Angular 、颜色和尺寸:

.container {
  width: 100%;
  padding: 50px;
  display: block;
}

h2 {
  font-size: 35px;
  line-height: 1.2;
  margin: 0;
  width: 500px;
}

.heading-border {
  background: 
    linear-gradient(-225deg,transparent 5px, pink 0) bottom left, /*225 = 180 + 45 */
    linear-gradient(-45deg ,transparent 5px, pink 0) bottom right;
  background-size: 51% 7px;
  background-repeat: no-repeat;
}


body {
 background:linear-gradient(to right,yellow,blue);
}
<div class="container">
  <h2>This is heading <span class='heading-border'>this is stylish heading line</span></h2>
</div>

关于html - 使标题下划线时尚的不同方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56472483/

相关文章:

javascript - 按住鼠标按钮且光标不在视口(viewport)外时如何检测鼠标离开?

HTML 和 CSS 根据窗口大小更改表格布局

javascript - 使用 getElementsByTagName 从 div 检索值

javascript - 如何将 WebGLRender 背景设置为透明

html - 对齐 HTML 元素

javascript - 修复有问题的布局/如何获取元素高度?

html - IE9溢出隐藏问题

html - 空的 div 不会增长

jquery - 如何在 jQuery 中检索 HTML 属性值?

html - 处理 flexbox 和容器缩小到内容的宽度