![](/img/trans.png)
[英]How to make a div cover the whole width of a webpage, not just the viewport?
[英]How to make <div> cover whole page and not only viewport
我正在嘗試讓一個 div 覆蓋我的整個頁面。 目前,問題在於它僅覆蓋視口的大小(例如 1920x1080px)。
這就是我目前正在使用的 div 的 CSS :
#cursor-container {
position: absolute;
z-index: 99999;
pointer-events: none;
overflow-x: auto;
background-color: rgba(0, 0, 0, 0.25);
top: 0;
left: 0;
bottom: 0;
right: 0;
height: 100%;
width: 100%;
}
目前,它看起來像這樣:
但它應該看起來像這樣:
我怎樣才能解決這個問題?
首先,確保您使用的div
是body
元素的子元素,然后將 position 更改為position: fixed;
,
#cursor-container {
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
height: 100%;
width: 100%;
z-index: 99999;
pointer-events: none;
overflow-x: auto;
background-color: rgba(0, 0, 0, 0.25);
}
這將確保您的 div 保持固定在屏幕上,即使頁面向下滾動並且它將覆蓋整個屏幕
另外,將父級的寬度和高度也設置為 100%,
html, body {
width: 100%;
height: 100%;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.