1. 程式人生 > >width:100%以什麽為基準的測試

width:100%以什麽為基準的測試

盒模型 一個 rst cond png pos 測試 結果 總結

起初是遇到這樣一個問題:當盒模型設為box-sizing:border-box;(移動端上經常這麽幹)。子盒子的width:100%,子盒子的width等於父盒子contend的長度還是condend+padding+border的長度?

css和html:

技術分享 技術分享

結果:

技術分享(second的width)=(first的contend的長度)

接下來總結正常情況(box-sizing:contend- box)下width:100%的基準:

1.標準流中:子盒子處於標準流中,其width等於上一級父盒子的width(父盒子無論是浮動還是定位)

2.浮動的情況:子盒子浮動,同上

3.定位的情況:子盒子定位(position:relative或absolute),其width等於上層盒子中 最近的

position不為static的那個的width。

子盒子為position:fixed時,width以html為基準。

width:100%以什麽為基準的測試