Here's a new and improved answer!
To enhance your CSS, consider adding the following code:
.overlay_ {
position: fixed;
top: 0;
left: 0;
}
fixed
ensures that the element remains in place even when scrolling through the document.
If this solution proves helpful, don't forget to upvote so it can benefit more individuals!
Previous Answer ...
Incorporating the provided CSS into your existing code:
body {
margin: 0;
}
.overlay_ {
position: fixed;
width: 100vw;
height: 100vh;
background: rgba(0, 0, 0, 0.9);
z-index: 9999;
top: 0;
left: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8><meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="overlay_"></div>
</body>
</html>
body {
margin: 0;
}
Before
https://i.sstatic.net/EGy1C.png
After
https://i.sstatic.net/qA4ZM.png
body {
margin: 0;
}
.overlay_ {
position: absolute;
width: 100%;
height: 100vh;
background: rgba(0, 0, 0, 0.9);
z-index: 9999;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="overlay_"></div>
</body>
</html>