詳解CSS盒子距離計算

來源:互聯網
上載者:User
一、看如下例子:

(1)HTML部分內容

<body>       <ul>               <li>複仇時刻</li>               <li class="widthborder">莫羅請求布雷斯把小孩丹尼帶來神殿以避免惡魔奪取他的靈魂,作為回報他將驅除布雷斯身上的詛咒。</li>       </ul>       <ul>               <li>原始碼</li>               <li  class="widthborder">科爾突然驚醒發生自己在一輛高速行駛的列車上,他的身邊坐著一個素不相識的女子正在與自己講話。</li>       </ul></body>(2)CSS內容ul{   backgroud:#ddd;   margin:15px;   padding:5px;}li{   color:black;   background:#aaa;   margin:20px;   padding:10px;   list-style:none;}li.widthborder{   border-style:dashed;   border-width:5px;   border-color:black;   margin-top:20px;}

(3)計算的距離:

(4)解釋:

在標準流中:I、行內元素之間的水平margin是累加的 II、區塊層級元素之間的豎直margin是塌陷的 III、嵌套盒子若父親沒有指定大小,則預設設定其父盒子是恰好包含子盒子的大小;若父盒子指定了大小,當父盒子大小小於子盒子時,IE6會自動調整其父盒子的大小以適應內含項目關聯性,而firefox則不會自動調整。

相關文章

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.