html – 在CSS中使用background-image创建一个完美的虚线

我想在文本下方加一条虚线:

enter image description here

网页设计师设计了一个自定义点缀,所以我不能使用:

h2 {
    border-bottom: 4px dashed #fff;
    display:table;
}

因为它不符合.

我做了什么:我用点做了一个图像并用css定位它:

h2 {
    padding-bottom: 20px;
    display:table;
    background-image: url('../images/tiret.png');
    background-repeat: repeat-x;
    background-position: center bottom; 
}

它工作得很好,但根据文本的宽度,最后一个点可能会像你在这图片上看到的那样切割:

enter image description here

你对如何避免这种情况有什么建议吗?

解决方法

你可以使用border-image:

h1 {
  display: inline-block;
 border-style: solid;
border-width: 0px 0px 12px;
-moz-border-image: url(http://yurigor.com/wp-content/images/goldstar.png) 0 0 286 round;
-webkit-border-image: url(http://yurigor.com/wp-content/images/goldstar.png) 0 0 286 round;
-o-border-image: url(http://yurigor.com/wp-content/images/goldstar.png) 0 0 286 round;
border-image: url(http://yurigor.com/wp-content/images/goldstar.png) 0 0 286 round;
}
<h1>Hello world</h1>

Codepen here

online generator也很有用

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些