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