hrの上にカスタムデータ属性で設定したテキストを表示する
Result
hrに疑似要素を加えてテキストを表示させるtipsです
ただ、hrタグは終了タグがないためimgタグ同様、空要素扱いのハズなので仕様上どうなんだという疑問もあります
また、IEやEdgeでは表示に問題が生じる可能性があるようです
上記の件はこちらをご参照ください
(:before and :after to HR in Microsoft Edge and IE)
css
.hr-text {
line-height : 1em ;
position : relative ;
outline : 0 ;
border : 0 ;
color : black ;
height : 1.5em ;
opacity : . 5 ;
}
.hr-text:before {
content : '' ;
background : linear-gradient (to right , transparent , #818078 , transparent );
position : absolute ;
left : 0 ;
top : 50% ;
width : 100% ;
height : 1px ;
}
.hr-text:after {
content : attr (data-content);
position : relative ;
display : inline-block ;
color : black ;
padding : 0 . 5em ;
line-height : 1.5em ;
color : #818078 ;
background-color : #fcfcfa ;
}
|
html
< hr class = "hr-text" data-content = "東京" >
|
via
HR with centered text