2

I am trying to set background color to the pages in my React app. I want to set a background color extending to the full page length and width but I cannot do that, for forms or tables extending beyond, I set height/width or min-height/min-width to 100% and I get the result for larger contents but for smaller contents,I get this:

I want to have the entire page of blue color.

enter image description here

This is my css file

.body
{
   margin:0px 0px 0px 0px;
   background-color:#4086ef;
   padding:10px;
   height:100%;
   width:100%;
}

If I set height to 100vh, I get the undesired result but with contents going beyond the page.

(Content rendering is dynamic so I don't know when the content will go beyond and when not).

EDIT: The table doesn't squeeze along when I compress the window and neither does the overflowing part follow the background color but the height follows the background color even when scrolled.

Abdul Ahad
  • 1,221
  • 2
  • 16
  • 28

3 Answers3

5

You just need to add height:100vh.So that it will cover your whole screen.

Arjun
  • 1,294
  • 13
  • 24
  • Worked but with min-height:100vh, though adding 100vh extends the page length and gives a scrollign option when not needed. Also, what is the difference between % and vh? I know vh gives value relative to the browser height. – Abdul Ahad Jun 12 '19 at 06:25
  • 100vh means 100% viewport height where 100% means parent's element height.Usually both works same in body tag because its our parent element.Also if 100vh gives you scrollbar then you can set overflow:hidden property in body tag.But normally 100vh wont give scrollbar.There might be other reasons of the scrollbar. – Arjun Jun 12 '19 at 06:30
0

Try with this

* {
    box-sizing: border-box;
}

body {
    margin: 0;
}

div {
    background: red;
    color: white;
    min-height: 100vh;
    padding: 10px;
}
<div>
    Test
</div>
Lalji Tadhani
  • 14,041
  • 3
  • 23
  • 40
-1

You can use: height: 100% !important;

Le Quang
  • 515
  • 4
  • 10