css實現中間文字兩邊橫線效果


1. vertical-align屬性實現效果:

vertical-align 屬性設置元素的垂直對齊方式。

該屬性定義行內元素的基線相對於該元素所在行的基線的垂直對齊。允許指定負長度值和百分比值。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<div class= "header" >
     <span class= "line" ></span>
     <span class= "text" >中間文字,兩邊橫線</span>
     <span class= "line" ></span>
</div>
 
<style>
.header
{
     width : 400px ;
     height : 36px ;
     line-height : 36px ;
     border : 1px solid green ;
     text-align : center ;
}
.line
{
     display :inline- block ;
     width : 100px ;
     border-top : 1px solid #cccccc ;
     vertical-align : 5px
  //看到網上有把.text設置為 vertical-align : -5px 的,試了一下感覺和.header設置的line-height有沖突,效果不太合適。所以將vertical-align設置到.line上了
}
</style>

2. css偽類實現效果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<div class= "header" >
     <div>中間文字,兩邊橫線</div>
</div>
 
<style>
     .header
     {
         width : 400px ;
         height : 36px ;
         line-height : 36px ;
         text-align : center ;
         border : 1px solid green ;
         position : relative ;
     }
     .header div:before,.header div:after
     {
         position : absolute ;
         background : #ccc ;
         content : "" ;
         height : 1px ;
         top : 50% ;
         width : 100px ;
     }
     .header div:before{ left : 10px ;}
     .header div:after{ right : 10px ;}
</style>

總結
 

以上所述是小編給大家介紹的css實現中間文字兩邊橫線效果 

 

轉自於;https://www.jb51.net/css/642211.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM