margin 碰到過的重疊問題

來源:互聯網
上載者:User

標籤:ges   class   code   htc   order   border   image   設定   img   

雙倍margin

稍微記錄一下,因為常忘

float + margin,實際邊距會變成設定值的雙倍。

解決辦法是 將元素設為 display:inline

最好要瞭解 IE的 haslayout 問題

 

垂直方向的margin重疊

以前一直知道 相鄰的兩個塊元素 在垂直方向margin重疊問題。

但是沒有考慮過 父元素和 第一個子項目的重疊情況

代碼如下:

        <div class="wrap">            <div class="one">margin 20px</div>            <div class="two">margin 20px</div>        </div>        <div class="wrap2">margin-top 50px 測試跟wrap的距離</div>
    .wrap {        margin: 0;        background-color: lightcoral;        .one {            margin: 20px;            background-color: lightblue;        }        .two {            margin: 20px;            background-color: lightgreen;        }    }    .wrap2 {        margin-top:50px;        background-color:lightgoldenrodyellow;        height:200px;    }

 

 

 

如果 wrap 包含塊沒有設定padding或border的話,wrap塊的外邊距會跟子項目重疊。

添加了border的效果如下。

 

margin 碰到過的重疊問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.