简体   繁体   中英

How to make the background color of CSS cover entire browser window?

How can I make the background color to cover the entire browser screen?

 .top{ background-color:green; color: white; height:1000px; display: flex; flex-direction: column; }
 <div className = "top"> <Header/> <Body /> </div>

I have tried making the height 100%. But it does not work at all. How can I fix it?

Just target the body , see code below.

 body { background-color: black; }
 <div> </div>

Additionally, if you want to use the div you can add 100vh and 100vw ;

 .top { background-color: green; color: white; display: flex; flex-direction: column; width: 100vw; height: 100vh; }
 <div class="top"> <Header/> <Body/> </div>

Apply background-color directly to <html> :

 html, body { background-color: black; }

You can use 100vh. This will make the html element take up the entire height of the users screen. Read more here: https://developer.mozilla.org/en-US/docs/Web/CSS/length

.top{
    background-color:green;
    color: white;
    height:100vh;
    display: flex;
    flex-direction: column;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM