センターに配置したテキストの両側を線で挟むやつ
Result
よくあるやつです。ベーシックな方法、spanを使わないパターン、背景(白)を使わないパターンもあります
css
h 2 .background {
position : relative ;
z-index : 1 ;
}
h 2 . background :before {
border-top : 2px solid #dfdfdf ;
content : "" ;
margin : 0 auto ;
position : absolute ;
top : 50% ;
left : 0 ;
right : 0 ;
bottom : 0 ;
width : 95% ;
z-index : -1 ;
}
h 2 .background span {
background : #fff ;
padding : 0 15px ;
}
h 2 .double:before {
border-top : none ;
}
h 2 .double:after {
border-bottom : 1px solid blue ;
box-shadow : 0 1px 0 0 red ;
content : "" ;
margin : 0 auto ;
position : absolute ;
top : 45% ;
left : 0 ;
right : 0 ;
width : 95% ;
z-index : -1 ;
}
h 2 .no-background {
position : relative ;
overflow : hidden ;
}
h 2 .no-background span {
display : inline-block ;
vertical-align : baseline ;
position : relative ;
padding : 0 20px ;
}
h 2 .no-background span:before,
h 2 .no-background span:after {
content : '' ;
display : block ;
width : 1000px ;
position : absolute ;
top : 0.73em ;
border-top : 1px solid red ;
}
h 2 .no-background span:before {
right : 100% ;
}
h 2 .no-background span:after {
left : 100% ;
}
h 2 .no-span {
display : table ;
white-space : nowrap ;
}
h 2 .no-span:before,
h 2 .no-span:after {
border-top : 1px solid green ;
content : '' ;
display : table-cell ;
position : relative ;
top : 0.5em ;
width : 45% ;
}
h 2 .no-span:before {
right : 1.5% ;
}
h 2 .no-span:after {
left : 1.5% ;
}
|
html
< h2 class = "background" >線と被るタイトル</ h2 >
< h2 class = "background" >< span >線に挟まれたタイトル</ span ></ h2 >
< h2 class = "background double" >< span >二重線に挟まれたタイトル</ span ></ h2 >
< h2 class = "no-background" >< span >線に挟まれたタイトル(背景なし)</ span ></ h2 >
< h2 class = "no-span" >線に挟まれたタイトル(背景もspanもなし)</ h2 >
|
via
CSS line behind title text