在html中,可以通過(guò)在水平線標(biāo)簽中,使用style屬性添加外邊距樣式來(lái)設(shè)置水平線與文字的距離。而外邊距樣式可以使用margin、margin-top或margin-bottom屬性來(lái)設(shè)置。
本教程操作環(huán)境:windows7系統(tǒng)、CSS3&&HTML5版、Dell G3電腦。
html設(shè)置水平線與文字的距離
<div> 文字--沒(méi)有設(shè)置距離 <hr/> 文字 </div> <div> 文字 <hr style="margin-top: 20px"/> 文字 </div> <div> 文字 <hr style="margin-bottom: 20px"/> 文字 </div> <div> 文字 <hr style="margin: 20px 0 30px;"/> 文字 </div>
效果圖:
說(shuō)明:
1、margin屬性
margin簡(jiǎn)寫屬性在一個(gè)聲明中設(shè)置所有外邊距屬性。該屬性可以有1到4個(gè)值。
實(shí)例:
margin:10px 5px 15px 20px;
-
上邊距是 10px
-
右邊距是 5px
-
下邊距是 15px
-
左邊距是 20px
margin:10px 5px 15px;
-
上邊距是 10px
-
右邊距和左邊距是 5px
-
下邊距是 15px
margin:10px 5px;
-
上邊距和下邊距是 10px
-
右邊距和左邊距是 5px
margin:10px;
-
所有四個(gè)邊距都是 10px
2、使用margin-top、margin-bottom屬性
-
margin-top:設(shè)置元素的上外邊距
-
margin-bottom:設(shè)置元素的下外邊距
(學(xué)習(xí)視頻分享:css視頻教程)