第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

浮動元素撐開父元素的區(qū)別

浮動元素撐開父元素的區(qū)別

海綿寶寶撒 2019-04-13 08:46:19
大家都知道position設置為absolute以及float定位會使元素脫離正常流,如果父元素沒有設置高度的話,他們不會把父元素的高度撐開。對于float元素可以把父元素設置overflow:hidden或者其他可以為父元素創(chuàng)建BFC的方法來解決這個問題,但是為什么對于絕對定位的元素這些辦法行不通呢?求指教
查看完整描述

2 回答

?
神不在的星期二

TA貢獻1963條經(jīng)驗 獲得超6個贊

W3C標準的算法里,float可能參與父級高度計算,但position:absolute;始終不參與父級計算。就是這樣設計的,沒轍:
W3CCSS2.110.6.3規(guī)定了未創(chuàng)建BFC的非替換塊級元素的高度計算規(guī)則:
Thissectionalsoappliestoblock-levelnon-replacedelementsinnormalflowwhen'overflow'doesnotcomputeto'visible'buthasbeenpropagatedtotheviewport.
If'margin-top',or'margin-bottom'are'auto',theirusedvalueis0.If'height'is'auto',theheightdependsonwhethertheelementhasanyblock-levelchildrenandwhetherithaspaddingorborders:
Theelement'sheightisthedistancefromitstopcontentedgetothefirstapplicableofthefollowing:
thebottomedgeofthelastlinebox,iftheboxestablishesainlineformattingcontextwithoneormorelines
thebottomedgeofthebottom(possiblycollapsed)marginofitslastin-flowchild,ifthechild'sbottommargindoesnotcollapsewiththeelement'sbottommargin
thebottomborderedgeofthelastin-flowchildwhosetopmargindoesn'tcollapsewiththeelement'sbottommargin
zero,otherwise
如上述分點,分項1定義了line-box撐高容器,分項2和3定義了常規(guī)流塊級元素撐高容器(margin折疊與否的兩種情況),否則為0。
W3CCSS2.110.6.7規(guī)定了創(chuàng)建了BFC的元素(blockformattingcontextroots)的高度計算規(guī)則:
Ifitonlyhasinline-levelchildren,theheightisthedistancebetweenthetopofthetopmostlineboxandthebottomofthebottommostlinebox.
Ifithasblock-levelchildren,theheightisthedistancebetweenthetopmargin-edgeofthetopmostblock-levelchildboxandthebottommargin-edgeofthebottommostblock-levelchildbox.
Absolutelypositionedchildrenareignored,andrelativelypositionedboxesareconsideredwithouttheiroffset.Notethatthechildboxmaybeananonymousblockbox.
Inaddition,iftheelementhasanyfloatingdescendantswhosebottommarginedgeisbelowtheelement'sbottomcontentedge,thentheheightisincreasedtoincludethoseedges.Onlyfloatsthatparticipateinthisblockformattingcontextaretakenintoaccount,e.g.,floatsinsideabsolutelypositioneddescendantsorotherfloatsarenot.
這里規(guī)則大致跟上方一樣,不同點在于margin不再折疊和float高度參與計算。
總之呢,在“撐高父容器圈”里面沒有絕對定位元素的地位。
                            
查看完整回答
反對 回復 2019-04-13
?
明月笑刀無情

TA貢獻1828條經(jīng)驗 獲得超4個贊

position為absolute的元素是相對于離他最近的position不為static的父級元素定位的,它不會占據(jù)父元素的空間,所以也不會撐起父級元素,這點和設置float的元素不一樣,唯一的辦法是給父級元素設置高度。
                            
查看完整回答
反對 回復 2019-04-13
  • 2 回答
  • 0 關注
  • 463 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號