???? CSS? Float ??? ?? ??? ???????. CSS?? Float ??? ??? ? ????? ?????? ?? ??? ???????.
1. ???? ??
1. ?? ??? ???? ?????.
2. ?? ??? ??? ????.
4. ??? Adapt? ??? ??? ? ??? ?? ?? ??? ? ????.2. ?? ?? ??
?? ??? ???:img label? img? ???? ?? ??? ???? ??? ?????.
<img src="../img/a.jpg" style=" width: 100px; height: 200px; float: left;" alt=""> ????????<p>001文件內(nèi)容文件內(nèi)容文內(nèi)容文件內(nèi)容<br/> ????????文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)內(nèi)容文件內(nèi)容<br/> ????????文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容<br/>? ????????文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文內(nèi)容文件內(nèi)容文件內(nèi)容<br/> ????????<p>p標簽文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文容文件內(nèi)容文件內(nèi)容文件內(nèi)容</p> ????????<p>p標簽文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容</p> ????????文件內(nèi)容文件內(nèi)容文件內(nèi)容文件件內(nèi)容文件內(nèi)容文件內(nèi)容<br/> ????????文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容<br/>? ????????文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)容文件內(nèi)內(nèi)容文件內(nèi)容<br/> ????????文件內(nèi)容文件內(nèi)容文件內(nèi)容文件容文件內(nèi)容文件內(nèi)容<br/> ????????文件內(nèi)容文件內(nèi)容文件內(nèi)容文件容文件內(nèi)容文件內(nèi)容<br/> ????????</p>
2.1 ?????
??? ??? ?? ??? ??? ??, ??? ??? ?? ?? ???clear float? ????. ??? ??? ?? ??? ?? ??? ??? ?? ??? ?????.
<p style="width: 100px; height: 200px; background: red;float: left;" >001</p>? <p style="width: 100px; height: 200px; background: gray;float: none;" ><p>002</p></p>001 ???, 002? ????? ??? 002 ?? ??? 001? ??? ??? ??? 001 ??? ?????.
3. ??? ? ?? ?? ??
? ????: ?? ??? ???? ??? ?? ?? ??? ?? ? ?? ?????. ?? ??1. ?? ??? ?????(??? ??? ?????).wrap{ ???????????background:red;? ???????????padding:10px; ???????????width:auto; ????????} ????????.left{ ????????????background:gray; ????????????width:200px; ????????????height:100px; ????????????float:left; ????????} ????????.right{ ????????????background:yellow; ????????????width:100px; ????????????height:100px; ????????????float:left; ????????}
<p class="wrap"> ????????<p class="left">left</p> ????????<p class="right">right</p> </p>
.wrap{ ???????????background:red;? ???????????padding:10px; ???????????float:left; ????????}? ????????.left{ ????????????width:100px; ????????????background:gray; ????????} ????????.right:{ ????????????width:200px; ????????????background:yellow; ????????}
<p class="wrap"> ????????<p class="left">left</p> ????????<p class="right">right</p> </p>
2. ?? ?? ?? ??
?? BFC? IFC? ? ?? ?? ??? ???? ???. ???? ? ? ??? ???? ???? ???? ???? ?? ?????. 1.BFC (block-levelformatting context)????? ????? ????, ?? ??? ????? ????, ???? ??? ??? ????. 1.1 ?? ??? ???? ?????. 1.2 ??? ?? ??? ??? ??? ?? ?????. ??? BFC? ??? ? ??? ??? ??? ????. 1.3 BFC ??? ??? ????. float.head{ ????????????background:pink; ????????????margin:?20px?0px; ????????????height:100px; ????????} ????????.wrap{ ???????????background:red;? ???????????padding:10px; ???????????margin:20px?0px; ???????????overflow:hidden; ????????}? ????????.left{ ????????????width:100px; ????????????background:gray;? ????????????margin:10px?0px; ????????} ????????.right:{ ????????????width:200px; ????????????background:yellow;?? ????????????margin:20px?0px; ????????}
<p class="head">head</p> ????<p class="wrap"> ????????<p class="left">left</p> ????????<p class="right">right</p> ????</p>
line-height? ?? ?????.
? ??? ?? ????? ?? ??? ??? ?????.3. ???
主要根據(jù)BFC的原理實現(xiàn),因為BFC的渲染的是整塊區(qū)域,也就會計算出寬、高。這也是傳說中的清除浮動的方案
3.1 父容器創(chuàng)建BFC方法
3.1.1 創(chuàng)建BFC的方法
a) Float除了none以外的取值;
b) Overflow除了visible以外的值;
c) Display值為table-cell、table-caption、inline-block、flex、inline-flex等
d) Position值為absloute、fixed
e) Fieldset元素
3.1.2 清除浮動
a) Float、overflow、display三種方式都可以清除浮動,但position、fieldset雖然創(chuàng)建了bfc但不可以清除浮動(也就是不能解決高度塌陷的問題)。主要原因為:position、fieldset都需要子元素來撐開父容器的高度,但子元素浮動后又不存在高度,所以失效。
b) Float、overflow、display示例代碼:
.wrap{ ????????????background:?gray; ????????????padding:?10px; ????????????overflow:?auto; ????????} ????????.left,?.right{ ????????????background:?red; ????????????float:?left; ????????????width:?200px; ????????????height:?100px; ????????} ????????.right{ ????????????background:?yellow; ????????} ????????.footer{ ????????????background:?pink; ????????}
<p class="wrap" > ????????<p class="left">left</p> ????????<p class="right">right</p> ????</p> <p class="footer">footer</p>
3.1.3 最后一個子元素clear:both
利用clear:both觸發(fā)父容器重新計算高度的原理實現(xiàn),示例代碼如下:
.wrap{ ????????????background:?gray; ????????????padding:?10px;? ????????} ????????.left,?.right{ ????????????background:?red; ????????????float:?left; ????????????width:?200px; ????????????height:?100px; ????????} ????????.right{ ????????????background:?yellow; ????????} ????????.footer{ ????????????background:?pink; ????????} ????????.clear{ ????????????clear:?both; ????????????zoom:?1; ????????}
<p class="wrap" > ????????<p class="left">left</p> ????????<p class="right">right</p> ????????<p class="clear"></p> ????</p> <p class="footer">footer</p>
3.1.4 After添加最后一個子元素
利用css的:after偽元素實現(xiàn),動態(tài)插入元素并清除浮動:
.wrap{ ????????????background:?gray; ????????????padding:?10px;? ????????} ????????.wrap:after{ ????????????content:?''; ????????????display:?block; ????????????overflow:?hidden; ????????????clear:?both; ????????} ????????.left,?.right{ ????????????background:?red; ????????????float:?left; ????????????width:?200px; ????????????height:?100px; ????????} ????????.right{ ????????????background:?yellow; ????????} ????????.footer{ ????????????background:?pink; ????????}
<p class="wrap" > ????????<p class="left">left</p> ????????<p class="right">right</p>? ????</p> <p class="footer">footer</p>
4. 總結(jié)
1. 利用bfc方式清除浮動,簡單、瀏覽器支持良好,但在IE6-版本支持存在問題。但是存在以下局限性,要適環(huán)境而用:
??? a) Overflow方式:滾動條會被隱藏,如果子內(nèi)容超高則存在顯示不全的問題;
??? b) Float方式:讓父容器浮動,那么就存在對父容器同輩元素的影響;
??? c) Dipslay方式:讓父容器變?yōu)閠able或者flex等,都存在不明確的影響,大家都不推薦使用。
2. 最佳解決方案:利用:after添加一個偽元素并給予clear:both和zoom:1來實現(xiàn)清除浮動,兼容性好,對環(huán)境影響最小。
相信看了本文案例你已經(jīng)掌握了方法,更多精彩請關(guān)注php中文網(wǎng)其它相關(guān)文章!
推薦閱讀:
? ??? CSS? Float ??? ?? ??? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

CSS? ??? ??? ????? ?? ??? ???????. 1. ?? ??? ???? ??? ??? ???? ?? ?? (? : ???), 16 ? ?? (? : #FF0000), RGB ? (? : RGB (255,0,0)), HSL ? (? : HSL (0,100%, 50%) ? RGBA ?? HSLA (RGBA) (255,0.0); 2. H1 ~ H6 ??, ?? P, ?? A? ?? ???? ?? ? ?? ??? ??? ?? ? ? ???? (A : A : ??, A : ??, A : Active, Div, Span ?; 3. ???

USEAUTOMATEDTOOLSPURGECSSORUCNSSCANANDREMOVEUNUSEDCSS; 2. INTEGRATEPURGINGINTOYOURBUILDPROCESSVIAWEBPACK, vite, ortailwind'ScontentConfiguration; 3.auditcsSusagewithchromedevToolsCovereAvoidtoidrestyledingneatiledneatiled? 3.auditcsSusage

astackingcontextiself-containdlayerincssthatcontrolsthez-orderofoverlappingElements, ???? wherenestedcontextsrestrictz-indexintermation;

? ???? CSS ??? ??? ?? ?? ??? ?? ? ??? ?? ????. 1. ?? (px)? ?? ? ???? ?? ??? ???? ? ????? ?? ? ????? ????? ????. 2. ??? (%)? ?? ????? ?? ???? ???? ????? ????? ???? ??????? ?????. 3.EM? ?? ?? ??? ??????, REM? ?? ?? ??? ??????, ?? ?? ? ?? ?? ??? ?????. 4. ??? ?? (VW/VH/VMIN/VMAX)? ?? ??? ?? ???? ?? ?? ?? ? ?? UI? ?????. 5. ??, ??, ?? ? ?? ?? ???? ???? ??, ?? ?? ????? ? ????, ?? ???? ???? ? ??? ??? ??????. ??? ??? ???? ??? ??? ???? ?? ?? ???? ? ????.

?? ??? ?? ?? ??? ??? ??? ???? ? ?????. 1. ?? ?? : Blur (10px) ? ?? ??? ???? ???? ?? ??? ?????. 2. ??, ??, ?? ?? ?? ?? ?? ??? ???? ?? ? ? ????. 3. ?? ?? ???? ?? ???? ??? ??? ?????????. 4. ??? ????? ??? ??? @Supports? ?? ???? ???? ???? ? ??? ? ????. 5. ??? ????? ?? ??? ?? ?? ??? ?? ???? ?????. ? ??? ?? ?? ????? ???? ?????.

??? ???? ?? ???? ?? ?? ??? ???????. 1. A ?? : ?? Unreached ?? ???? ???? ??, 2. A : ??? ? ??? ????? ??, 3. ?? ?? ??? ????? ??, 4 : ?? ?? ???? ????? ???. ??, ?? : ??? ? ??? ??? ????? ??? ???? ???? ???? ???? ? ????. ?? Border-Bottom ?? ????? ??? ???? ?? ??? ??? ??? ??? ??? ???? ??? ? ? ????.

???-?? : ??? ???? ???? ?? ??? ?????. 2. Flexbox? ?? ??? ?????? : ?? ? ??? ??? : ?? ? ?? ???? ???? ?? ??; 3. ?? ?? ???? ???? ??? ??? ? ???? ???? ?? ??? ?? ? ????. 4. ?? ???? ??? ??? ?? ? ? ???? : 50%, ?? : 50%? ?? : ??? ???? ?? ?? (-50%, -50%); 5. CSSGRID? ?? ?? : ??? ??? ?? ? ??? ?? ? ? ????. ?? ?????? Flexbox ?? ???? ?? ???? ?? ????.

??? ???? ??? ??? ????? ???? ???? ?? CSS ??????. ??? ?? ???? ???? ?? HTML ??? ??? ????? ?? ? ????. ???? ?? ??? ??? ??? ? ?????? ????? ?????? ?????? ??? ? ????. ???? ?? ???? ?????? ??? ??? ??? ?????. ??? ??? ??? ?? ??? ??? ???? ?? ????????. ???? ???? ???? ?? ? ?? ?? ??, ?? ?? ??, ?? ?? ?? ? ?? ?? ???? ?????. ??? ???? ???? ???? ??? ???? ???? ????? ??? ???? ??? ???? ? ? ????.
