日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

简单实现顶部固定,中部自适应布局

發布時間:2023/12/10 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 简单实现顶部固定,中部自适应布局 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ? ? ? 最近在重構web導航的時候就發現一個問題,如何實現頂部固定,中部自適應的布局。

? ? ? ? 很多人會認為這很簡單啊,頂部使用position: fixed;就可以實現。

<!DOCTYPE html> <html lang="zh"><head><meta charset="UTF-8"><title>頂部固定,中部自適應</title><style type="text/css">* {margin: 0;padding: 0;}.hd {position: fixed;z-index: 99;top: 0;width: 100%;height: 20px;padding: 15px 0;text-align: center;color: #fff;background: #f00;}.bd {width: 100%;margin-top: 50px;padding: 15px 0;text-align: center;color: #fff;background: #00f;}</style> </head><body><header class="hd">我是固定頭部</header><div class="bd">我是中部部分<p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p></div> </body></html>

這種做法確實簡單,但是,請看清題目,頂部固定,中部自適應。(頂部不包括滾動條)

花了一點時間的思考,終于想出來了,中部使用position:absolute;就可以實現。

<!DOCTYPE html> <html lang="zh"><head><meta charset="UTF-8"><title>頂部固定,中部自適應</title><style type="text/css">* {margin: 0;padding: 0;}.hd {width: 100%;height: 50px;padding: 15px 0;text-align: center;color: #fff;background: #f00;}.bd {position: absolute;top: 50px;/* 往下移頂部的距離 */bottom: 0;/* 底部貼邊 */overflow: auto;/* 溢出的部分自適應 *//* 不設置高度 */width: 100%;padding: 15px 0;text-align: center;color: #fff;background: #00f;}</style> </head><body><header class="hd">我是固定頭部</header><div class="bd">我是中部部分<p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p><p>超出的部分滾動</p></div> </body></html>

PS:這種做法的好處是不占頂部寬度,頂部100%顯示全部區域,特別適用于針對右上角有菜單導航的頁面。

?

轉載于:https://www.cnblogs.com/Sroot/p/7636851.html

總結

以上是生活随笔為你收集整理的简单实现顶部固定,中部自适应布局的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。