2017-05-04 49 views
1

Look at the sample image文本下划线或边框底部自定义

你能用css实现这种下划线吗?我试着做下面的方式,但我不能提前做出细线,然后再次进行粗线末

h1 { 
 
    font-weight: 300; 
 
    display: inline-block; 
 
    padding-bottom: 5px; 
 
    position: relative; 
 
} 
 
h1:before{ 
 
    content: ""; 
 
    position: absolute; 
 
    width: 25%; 
 
    height: 1px; 
 
    bottom: 0; 
 
    left: 1%; 
 
    border-bottom: 10px solid blue; 
 
     h1 { 
 
     content: ""; 
 
     position: absolute; 
 
     width: 50%; 
 
     height: 1px; 
 
     bottom: 0; 
 
     left: 5%; 
 
     border-bottom: 10px solid blue; 
 
    } 
 
}
<h1>test text for show</h1> 
 

 

 
<p>Desired final style</p> 
 
<img src="https://i.stack.imgur.com/POrU6.png">

回答

4

使用h1为薄边框线和粗端

注伪,CSS不允许嵌套在一个又一个规则,因为你曾与h1:beforeh1,对于需要SCSS或者SASS

h1 { 
 
    font-weight: 300; 
 
    display: inline-block; 
 
    padding-bottom: 5px; 
 
    position: relative; 
 
    border-bottom: 1px solid blue; 
 
} 
 

 
h1::before, 
 
h1::after { 
 
    content: ""; 
 
    position: absolute; 
 
    width: 30%; 
 
    height: 9px; 
 
    bottom: -5px; 
 
    left: 0; 
 
    background: #900; 
 
} 
 
h1::after { 
 
    left: auto; 
 
    right: 0; 
 
}
<h1>test text for show</h1>

+0

谢谢朋友,优秀的解决方案!问候! – Daniel

+0

@丹尼尔不客气。请考虑接受我的回答以及 – LGSon

+0

准备好的朋友,我不能给你票,因为我缺乏15个声望!但检查出来!问候和感谢! – Daniel

1

例如低于校验

.underline-text4{ 
 
     position:relative; 
 
     padding-bottom:5px; 
 
     display:inline-block; 
 
     color:blue; 
 
     border-bottom:4px solid blue 
 
    } 
 
.underline-text4::before{ 
 
    position: absolute; 
 
    bottom:-7px; 
 
    height:10px; 
 
    width:50px; 
 
    left:0; 
 
    content:""; 
 
    background:red; 
 
}  
 

 
.underline-text4::after{ 
 
    position: absolute; 
 
     bottom:-7px; 
 
    height:10px; 
 
    width:50px; 
 
    right:0; 
 
    content:""; 
 
    background:red; 
 
}
<div class="underline-text4"> This is Underlined text 3 </div>

更多实例在

https://codepen.io/sajiddesigner/pen/QvgeGO

您可以使用不同的方法创建尽可能多的不同风格

+0

这个字面上看起来没什么像OP正在寻找的 – StefanBob

+0

我刚给他提示。让我为他更新答案。 :) –

+0

谢谢你的朋友,投票你的答案:D我喜欢你发布的示例样式!问候!! – Daniel