2016-04-24 7 views
2

私はdivのテキストを持っていますが、ボーダーボトムを追加しますが、ボトムラインの幅はテキストの幅と同じですが、このボトムラインをテキストよりもずっと小さくする方法はありますか?テキストのボーダーボトムの問題

enter image description here

マイコード:

.title-line { 
 

 
border-bottom: 1px solid rgba(0, 0, 0, 0.2); 
 
    font-family: lato; 
 
    font-size: 18px; 
 
    font-weight: normal; 
 
    padding: 0 0 1em; 
 
    text-align: center; 
 
}
<dt class="title-line">My Text Example</dt>

+0

申し訳ありませんが、私は – Robert

答えて

4

はい、あなたの代わりにborder-bottomの(::afterのような)擬似要素を使用することができます私は、この画像のようになりたいです。

.title-line { 
 
    position: relative; /* important for absolute child to work */ 
 
    font-family: lato; 
 
    font-size: 18px; 
 
    font-weight: normal; 
 
    padding: 0 0 1em; 
 
    text-align: center; 
 
} 
 

 

 
.title-line::after { 
 
    content: ''; /* required to display pseudo elements */ 
 
    height: 1px; /* this works like a border-width */ 
 
    width: 10%; /* you can use a percentage of parent or fixed px value */ 
 
    background: #CCC; /* the color of border */ 
 
    position: absolute; 
 
    bottom: 0; /* position it at the bottom of parent */ 
 
    margin: 0 auto; left: 0; right: 0; /* horizontal centering */ 
 
}
<dt class="title-line">My Text Example</dt>

+0

を理解していないが、あなたに感謝、私は問題を抱えている、より多くのテキストがあることができ、私は位置を使用することはできません。絶対のために:の後に、そこにありますどんな方法ですか? – Robert

+1

@RobertD AzizのCSSは、 'title-line'クラスが適用されたすべてのテキストに対して動作するはずです。そして、なぜあなたは絶対位置を使用できないのですか? –

+1

はい、実際には、これは私の間違いでした。申し訳ありません。アジズの答えは完璧です、あまりにも多くのアジズに感謝 – Robert

関連する問題