css中外邊距

來源:互聯網
上載者:User

標籤:lower   元素   images   pad   hid   最大   com   上下   lock   

1.內部元素設定margin等,父元素高度不能適應

 1 .classA { 2     height: 200px; 3     background-color: cornflowerblue; 4     overflow: hidden;   /*解決高度不能適應*/ 5 } 6 .classB { 7     width: 1000px; 8     height: 100px; 9     background-color: red;10     margin: 0 auto;11     margin-top: 50px;12 }13 14 <div class="classA">15     <div class="classB"></div>16 </div>

效果如。

2.div與div外邊距

 1 div { 2     width: 200px; 3     height: 200px; 4     margin: 20px; 5 } 6 .div1 { 7     background: red; 8 } 9 .div2 {10     background: yellow;11 }12 13 <div class="div1"></div>14 <div class="div2"></div>

div等塊元素,外邊距為兩者之間最大的。

3.span等行內元素,只有左右邊距,沒有上下邊距。且外邊距為兩者之和。

 

1 span {2     background: red;3     margin: 20px;4 }5 6 <span>111</span>7 <span>111</span>8 <span>111</span>

 

 

4、div 與span,塊元素與行內元素,div的外邊距是到span的文字內容邊緣。

 

.div2 {    background: yellow;  }span {    border: red 1px solid;    padding: 20px;}

 

 

.div2 {    background: yellow;    margin:10px;}span {    border: red 1px solid;    padding: 20px;}

 5.inline-block的元素,或者圖片與行內元素的內容的底部對齊,與padding等無關。

.div2 {    background: yellow;    display: inline-block;}span {    border: red 1px solid;    padding: 20px;                }

<div class="div2"></div>
<span>111</span>
<span>111</span>
<span>111</span>

 

 

css中外邊距

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.