這篇文章要跟大家介紹的內容是關於HTML5如何解決margin-top的塌陷問題(附代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <!DOCTYPE html>
<html lang= "en" >
<head>
<meta charset= "UTF-8" >
<meta name= "viewport" content= "width=device-width, initial-scale=1.0" >
<meta http-equiv= "X-UA-Compatible" content= "ie=edge" >
<title>Document</title>
<style>
.box{
width: 400px;
height: 400px;
background-color: red;
overflow: hidden;
}
.clearfix:before{
content: "" ;
display: table;
}
.box1{
width: 100px;
height: 100px;
background-color: green;
margin-top: 50px;
}
</style>
</head>
<body>
<p class = "box clearfix" >
<p class = "box1" ></p>
</p>
</body>
</html>
|
登入後複製
運行效果如下:

#相關推薦:
Html5中video標籤的用法:如何自動填入滿父div標籤
HTML5屬性:margin屬性的用法實例
以上是HTML5如何解決margin-top的塌陷問題(附程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!