``After resizing the window height, the overlay is not expanding to fill the entire

Check out my CSS and HTML code snippets below:

.overlay_ {
    position: absolute;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999; 
}

Html

 <body> <div class="overlay_"></div> </body>

I'm facing an issue where the overlay does not cover the entire screen when I resize the window. How can I make it fullscreen even if the window height changes?

https://i.sstatic.net/lAEOg.jpg

Answer №1

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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Function activation in Element requires a double click to initiate

I've encountered an issue with a web element I'm working on where the click function only triggers after the first click, rendering the initial click ineffective. Here's the code snippet in question: HTML: <div> <a href="#0" cla ...

A guide on embedding text onto the bottom of an image in Material-UI GridList using Reactjs

I'm currently developing a Mern-stack application and using Material-UI for the frontend. My GridList is functioning correctly, but I want to position my description text at the bottom of the image rather than in front of it. However, when I try to a ...

Creating a Phonegap hybrid application that uses JavaScript redirection can cause an absolute positioned element to intermittently blink, revealing the content that lies

Currently, I am developing a Cordova project for both iOS and Android platforms. Within my project, I have two main pages: index.html and home.html. Each page contains an absolute positioned div (with loading feature) that is visible by default. Here is t ...

What is the best way to send an object to Vue Component?

How can I properly call a Vue Component with a data object? The todo-item tag works as expected, but the todo-item2 tag does not produce any output. I was expecting the same result. Here is the HTML code: <div id="app"> <todo-item v-bind:te ...

The mx-auto class in Bootstrap does not properly center an element in the page

Recently, I've been working on a website that makes use of the Bootstrap 5 navbar. The design includes three navbar-navs: one with me-auto, another with mx-auto, and the last with ms-auto. Strangely enough, the navbar-nav with mx-auto, which is suppos ...

Animation of CSS elements sliding up on the page, with the element briefly appearing before the slide begins

My CSS animation involves a page scrolling from the bottom to the top when selected. The problem I'm facing is that the page briefly appears in its top position before disappearing to scroll from the bottom to the top. How can I prevent the page from ...

Having issues with Jsoup parser specifically on one URL

I'm currently utilizing Jsoup to retrieve the content of a webpage and parse it. public static void main(String[] args) throws IOException { Document document = Jsoup.connect("http://www.toysrus.ch/product/index.jsp?productId=89689681").get() ...

List style image does not serve its intended purpose

I attempted to personalize my webpage by adding an image to a list, but I couldn't get the list-style image to work. You can view the page at Below is the code I used: CSS /* Fleet List */ ul#flotta li { list-style-image:url("http://ctp.serviziew ...

The wrapper refuses to display the background image, although it functions properly on other HTML elements

Currently, I am attempting to assign a background to a wrapper in order to create an infinite sidebar. Strangely enough, the background applies correctly when I use the same CSS rules on any other HTML element except for .wrapper. Below is the HTML code: ...

Arrange the columns and rows in a neat layout for the ant design table

I have encountered an alignment issue with the ant design table while listing out my data. The columns are aligned to the right, but the titles for all columns should be aligned to the left by default. You can view the image illustrating this problem using ...

The Angular controller fails to display any data when inserted within double curly braces on the HTML page

I have been working on a basic binding application using TypeScript. I created a controller called 'bugCtrl' and it appears to be functioning correctly in debug mode (with console.log and alert statements). Below is the HTML code from my page: & ...

Django: The download page content is being downloaded by Internet Explorer instead of being rendered

I'm currently working on a website using the Django Web Framework. Everything looks great when I check it in browsers like Chrome, Safari, and Firefox. However, if I try to open the page in Internet Explorer, I encounter this issue: https://i.sstatic ...

CSS Background Image Properties

I'm struggling to display a background image on my HTML page. The image is saved in the same folder as the HTML file. <html> <head> <link rel="stylesheet" type="text/css" href="style/indexstyle.css" > <meta charset="ISO-8859-1"& ...

issue with using references to manipulate the DOM of a video element in fullscreen mode

My current objective is to detect when my video tag enters fullscreen mode so I can modify attributes of that specific video ID or reference. Despite trying various methods, I have managed to log the element using my current approach. Earlier attempts with ...

Setting the default position of a scrollbar

In the chat window on my website, users currently have to use the scrollbar to navigate between messages when the log is filled. I want the chat frame to automatically display the last message at the bottom without requiring users to scroll. Can this be ac ...

Issue with Three JS canvas not adjusting to fit mobile device window width

I'm currently exploring the world of 3D animations using Three JS and I've set out to create a project involving multiple spinning cubes. However, I've encountered an issue where the canvas doesn't resize correctly when zooming in or ou ...

Missing ng-required fields not displaying the has-error validation in AngularJS forms

While editing any part of their address, the user should see a red invalid border around each field to indicate that the full form is required. However, for some reason I can't seem to get the 'Address' field to display this border. The set ...

Unveil a portal to the identical webpage

My apologies for my English skills... Could anyone advise me on how to display an image? Hello, I am looking for a way to have a small window open on my site when a user clicks on the zoom icon, where I can describe a product. Any guidance on the HTML co ...

End of container Bootstrap 4 row with two columns at the edge

I'm currently working on an angular project with bootstrap 4. Within the container, there are two rows. I specifically want one row to always be positioned at the bottom of the container. Despite trying methods like justify-content: flex-end;, botto ...

Crafting a gap between a component and its border

Currently, I am faced with the challenge of creating spacing between an element and its outermost border. To clarify, I aim to incorporate two borders in between the element itself and the external boundaries of the box-model box. This will allow me to lev ...