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