消除絕對定位的影響
阿新 • • 發佈:2019-01-28
應用:
頁頭絕對定位,同級元素被覆蓋
頁頭絕對定位,內容隨頁面滾動
正常三個div塊:
當第一個元素絕對定位後,元素被覆蓋
若想像圖一展示,解決辦法:同級元素相對定位,定位width根據絕對定位的高度來定.<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>絕對定位</title> </head> <body> <div style="background-color:blue;height:100px;width:50%;position:fixed;"></div> <div style="background-color:pink;height:200px;width:30%;"></div> <div style="background-color:yellow;height:300px;width:40%"></div> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>絕對定位</title> </head> <body> <div style="background-color:blue;height:100px;width:50%;position:fixed;"></div> <div style="position:relative;top:100px;"> <div style="background-color:pink;height:200px;width:30%;"></div> <div style="background-color:yellow;height:300px;width:40%"></div> </div> </body> </html>