絕對定位和負邊距的應用

2022-08-11 06:27:10 字數 724 閱讀 9016

1方法:

a:父容器加相對定位

b:給字元素加絕對定位 

c:top left:50% 

d:margintop(height),marginleft(width)取子元素的一半

2.**舉例

3.結果:

1.作用:

可以實現讓中間的內容先載入出來

2.方法:

a:在預設情況下:給center加marginleft:20%、給left加margin-left: -80%;(負邊距方法)

b:在預設情況下:給main加position: relative; 給center加position: absolute; left: 20%; 給right加float: right; (相對定位方法)

3.**舉例

4.結果

執行前:

執行後:

margin 負邊距應用

最外層寬度 340 100 20 100 20 100 23 24.pp 28 次外層寬度 360 29 30.p 34 每個寬度100 20 35 36.c 43style 44head 4546 body 47 div class pp 48 div class p clearfix 49 di...

css div布局定位和邊距問題

1 當你在乙個大的容器裡面給兩個小的容器定位的時候 position absolute 這個容器相對于父元素定位,初始位置在父元素的左上角。位置。給元素排列位置,乙個元素佔滿一行,即使你設定了width也是沒有用的,雖然容器只使用你設定的寬度。但是當你設定了 float或者display inlin...

CSS浮動和定位 邊框邊距

盒子邊框邊距 margin 外邊距 padding 內邊距 top 上邊距 left 左邊距 right 右邊距 bottom 下邊距 border 邊框 content 內容 浮動float left float right float none 預設 定位position static 靜態定位...