[英]div height at 100% but there is space on top and/or bottom still
我正在嘗試制作一個側面導航欄,其position: fixed
和height: 100%
,但是當我嘗試這個時,總是還有空間,你可以看到下面和或高於div
的背景。 順便說一句,我也嘗試使height
像1000px
但我仍然有同樣的問題。
HTML:
<div id='navbar'></div>
CSS:
#navbar {
background-color:black;
width:100px;
height:100%;
z-index:99;
position:fixed;
left:-10px;
bottom:10px;
}
我猜你正在設置bottom: 10px
將你的#navbar
推到頂部,在那里你首先有10px
間距,這會在底部產生相同的間距。 你可以通過應用top: 0; bottom: 0;
來強制你的元素從它的父高度的開始/結束伸展top: 0; bottom: 0;
top: 0; bottom: 0;
(你應該刪除bottom: 10px;
)到#navbar
元素。
PS top: 0
是多余的,但是我已經設置它來演示這個概念。
https://jsfiddle.net/7oxyvab5/2/
#navbar {
background-color:black;
width:100px;
height:100%;
z-index:99;
position:fixed;
left:-10px;
bottom:0px;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.