2015-11-07 87 views
1

我有一个H2标签与CSS:如何将两种颜色应用于标题标签的底部边框?

h2 { 
    display: inline-block; 
    border-bottom: 3px solid #ffcc00; 
    padding-bottom: 30px; 
    color: #5e5e5e; 
    font-size: 23px; 
    font-weight: 400; 
    line-height: 18px; 
    text-align: left; 
    margin: 30px 3px; } 

它看起来就像是:

[1]

但我想,以填补不同的边框“宽度的休息”。它必须看起来像:

enter image description here

回答

1

HTML

<h2> 
    <span>Some header</span> 
</h2> 

CSS

h2 { 
    border-bottom-width: 1px; 
    border-bottom-style: solid; 
    border-bottom-color: lightgray; 
} 

span { 
    border-bottom-width: 3px; 
    border-bottom-style: solid; 
    border-bottom-color: orange; 
    padding: 30px 3px; 
    margin: 0 0 -2px 0; 
    display: inline-block; 
} 

DEMO:http://jsfiddle.net/neowar2x/3/

+1

它的作品,谢谢! :) – MuchaZ

0

使用伪类:afterhttp://www.w3schools.com/css/css_pseudo_classes.asp

h2{ 
    display: inline-block; 
    border-bottom: 3px solid #ffcc00; 
    padding-bottom: 30px; 
    color: #5e5e5e; 
    font-size: 23px; 
    font-weight: 400; 
    line-height: 18px; 
    text-align: left; 
    margin: 30px 3px; 
    position:relative; /*add this*/ 
} 

h2:after{ 
    content:''; 
    display:inline-block; 
    position:absolute; 
    width:80%; 
    background:#e6e6e6; 
    height:3px; 
    top:100%; 
} 
+0

它工作不正确。后:线比h2低得多。 – MuchaZ

相关问题