CSS高度塌陷問題解決方案

2022-08-30 09:51:12 字數 3508 閱讀 9873

高度塌陷的存在:原因分析

1doctype html

>

2<

html

>

3<

head

>

4<

meta

charset

="utf-8"

/>

5<

title

>

title

>

6<

style

type

="text/css"

>78

.box1

1314

.box2

3435

.box3

3940

style

>

41head

>

42<

body

>

4344

<

div

class

="box1"

>

45<

div

class

="box2"

>

div>

46div

>

4748

<

div

class

="box3"

>

div>

4950

body

>

51html

>

1

// 高度塌陷的解決方案一23

doctype html

>

4<

html

>

5<

head

>

6<

meta

charset

="utf-8"

/>

7<

title

>

title

>

8<

style

type

="text/css"

>910

.box1

5253

.box2

6061

.box3

6566

style

>

67head

>

68<

body

>

6970

<

div

class

="box1"

>

71<

div

class

="box2"

>

div>

72div

>

7374

<

div

class

="box3"

>

div>

7576

body

>

77html

>

1

doctype html

>

2<

html

>

3<

head

>

4<

meta

charset

="utf-8"

>

5<

title

>

title

>

6<

style

type

="text/css"

>78

.box1

1112

.box2

1920

/*21

* 解決高度塌陷方案二:

22* 可以直接在高度塌陷的父元素的最後,新增乙個空白的div,

23* 由於這個div並沒有浮動,所以他是可以撐開父元素的高度的,

24* 然後在對其進行清除浮動,這樣可以通過這個空白的div來撐開父元素的高度,

25* 基本沒有***

26*

27* 使用這種方式雖然可以解決問題,但是會在頁面中新增多餘的結構。

28*/

29.clear

3233

style

>

34head

>

35<

body

>

36<

div

class

="box1"

>

37<

div

class

="box2"

>

div>

38<

div

class

="clear"

>

div>

39div

>

40body

>

41html

>

1

doctype html

>

2<

html

>

3<

head

>

4<

meta

charset

="utf-8"

>

5<

title

>

title

>

6<

style

type

="text/css"

>78

.box1

1112

.box2

1920

/*通過after偽類,選中box1的後邊

*/21

/*22

* 可以通過after偽類向元素的最後新增乙個空白的塊元素,然後對其清除浮動,

23* 這樣做和新增乙個div的原理一樣,可以達到乙個相同的效果,

24* 而且不會在頁面中新增多餘的div,這是我們最推薦使用的方式,幾乎沒有***

25*/

26.clearfix:after

3435

/*36

* 在ie6中不支援after偽類,

37* 所以在ie6中還需要使用haslayout來處理

38*/

39.clearfix

4243

44style

>

45head

>

46<

body

>

47<

div

class

="box1"

>

48<

div

class

="box2"

>

div>

49div

>

50body

>

51html

>

CSS盒子塌陷問題解決方案

什麼是盒子塌陷?外部盒子本應該包裹住內部的浮動盒子,結果卻沒有。問題出現的原因 父元素只包含浮動元素,那麼它的高度就會塌縮為零 前提就是你們沒有設定高度 height 屬性,或者設定了為auto,就會出現這種情況,如果父元素不包含任何的可見背景,這個問題會很難被注意到。因為子元素設定了float屬性...

Jar Hell 問題解決方案

最近看到溫紹錦的jvm基礎,裡面看到這個jar hell問題的解決方法,之前遇到過一次,是乙個資源檔案,當時覺得挺麻煩,不知道還有這個方法,很棒,特地整理了下,記錄到這裡來,這個部落格開了好長時間了,一直以來也懶得寫東西,以後會堅持更新些。classloader classloader thread...

top K問題解決方案

1.使用最大最小堆。求最大的數用最小堆,求最小的數用最大堆。2.quick select演算法。使用類似快排的思路,根據pivot劃分陣列。3.使用排序方法,排序後再尋找top k元素。4.使用選擇排序的思想,對前k個元素部分排序。5.將1000 個數分成m組,每組尋找top k個數,得到m k個數...