HTML5如何解決margin-top的塌陷問題(附代碼)

來源:互聯網
上載者:User
這篇文章給大家介紹的內容是關於HTML5如何解決margin-top的塌陷問題(附代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所協助。

<!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;/* 解決margin-top塌陷問題 *//* 1.設定border padding *//* border: 1px solid green; *//* padding: 1px; *//* 2.設定overflow */overflow: hidden;}/* 3.通過偽類實際開發使用*/.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>

運行效果如下:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.