div 沾滿剩餘空間(不用js)
阿新 • • 發佈:2020-09-01
1需求:
1) 這個矩形的高度和瀏覽器視窗的高度相同,不能出現縱向滾動條
2)橙色部分高度固定,比如100px
3) 紫色部分填充剩餘的高度
實現功能圖如下:
利用position定位程式碼如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="佔領剩餘空間.css"/> <title>佔領剩餘空間</title> </head> <body> <div class="總框"> <div class="框1"></div> <div class="框2">safvawfesagsaerafeaf</div> </div> </body> </html>
樣式表:
*{ margin: 0px; padding: 0px; } .總框{ width: 100%; height: 100%; } .框1{ width:100%; height: 100px; background-color: orange; } .框2{ width: 100%; background-color: darkmagenta; position: absolute; top: 100px; left: 0px; bottom: 0px; color: white; }