css margin-top设置html元素之间的距离
生活随笔
收集整理的這篇文章主要介紹了
css margin-top设置html元素之间的距离
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
css margin-top屬性設置的是一個元素的頂端與另一個元素之間的距離。這個距離稱為上外邊距,本文章向大家介紹css margin-top屬性的用法和實例,需要的朋友可以參考一下。
margin-top:值(如:10px)例如:
margin-top:10px表示設置該對象上邊距離與上一個對象盒子距離為10像素
一般網站開發中,我們建議大家使用像素px作為margin-top的單位。?
?
<!DOCTYPE html> <html> <head> <style> p.ex1 {margin-top:2cm;} </style> </head> <body> <p>A paragraph with no margins specified.</p> <p class="ex1">A paragraph with a 2cm top margin.</p> <p>A paragraph with no margins specified.</p> </body> </html>在線運行
css margin-top介紹
css margin-top屬性指從某一元素的上邊框開始,到另外一個相鄰的元素的下外邊距之間的距離。每一個元素都存在著外邊距。兩個相鄰的元素之間是靠它們的外邊距排列在一起的。
語法:margin-top:值(如:10px)例如:
margin-top:10px表示設置該對象上邊距離與上一個對象盒子距離為10像素
css margin-top取值
margin-top的取值可以設置以下四種情況:| auto | 瀏覽器設置的上外邊距。 |
| length | 定義固定的上外邊距。默認值是 0。 |
| % | 定義基于父對象總高度的百分比上外邊距。 |
| inherit | 規定應該從父元素繼承上外邊距。 |
一般網站開發中,我們建議大家使用像素px作為margin-top的單位。?
?
css margin-top實例
設置一個class為ex1的p元素的上邊距與上一個HTML元素的上邊距為2cm<!DOCTYPE html> <html> <head> <style> p.ex1 {margin-top:2cm;} </style> </head> <body> <p>A paragraph with no margins specified.</p> <p class="ex1">A paragraph with a 2cm top margin.</p> <p>A paragraph with no margins specified.</p> </body> </html>在線運行
原文地址:http://www.manongjc.com/article/1264.html
其他閱讀:
css :after偽類選擇器使用詳解css :active選擇器設置被激活鏈接的樣式css 設置margin-top或margin-bottom失效不取作用的解決方法css margin-bottom設置HTML元素之間底(下)邊距離css margin:0 auto無法居中的原因轉載于:https://www.cnblogs.com/myhomepages/p/6010068.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的css margin-top设置html元素之间的距离的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spring+mybatis+sprin
- 下一篇: HTTP 协议详解(超级经典)