1

i'm writing a webpage and i can't make the div elements to full the screen.

I'm using a mac OSX and Safari, Google Chrome and Firefox browsers to view the page.

This is the my code inside the body:

* {
  margin: 0px;
  padding: 0px;
  border: 0px;
}

body {
  background-color: grey;
  height: 100%;
  position: absolute;
  margin: 0px;
  padding: 0px;
}

.register {
  display: table;
  width: 100%;
  min-height: 25%;
}

.FAQ {
  display: table;
  width: 100%;
  height: 25%;
}

.sponsors {
  display: table;
  width: 100%;
  height: 25%;
}

.footer {
  display: table;
  width: 100%;
  height: 25%;
}
<div class="register"></div>
<div class="FAQ"></div>
<div class="sponsors"></div>
<div class="footer"></div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Manuel Gijón
  • 138
  • 1
  • 11

2 Answers2

0

add this line to each div

table-layout:fixed;

for example

.register{
    display: table;
    width: 100%;
    min-height: 25%;
   table-layout:fixed; /* this line was added */
  }
ashish singh
  • 6,526
  • 2
  • 15
  • 35
0

You didn't specify a width to the body element and since you made it positioned and there is no content inside its width will by default be 0.

As a side note, you see the grey color cover the whole screen due to background propagation and not because the body is already full width, so this may create confusion.

Here is the initial code with background color of html changed so you can clearly see that the body has 0 width:

* {
  margin: 0px;
  padding: 0px;
  border: 0px;
}
html {
 background:pink;
}
body {
  background-color: grey;
  height: 100%;
  position: absolute;
  margin: 0px;
  padding: 0px;
}

.register {
  display: table;
  width: 100%;
  min-height: 25%;
  background: red;
}

.FAQ {
  display: table;
  width: 100%;
  height: 25%;
  background: blue;
}

.sponsors {
  display: table;
  width: 100%;
  height: 25%;
  background: green;
}

.footer {
  display: table;
  width: 100%;
  height: 25%;
  background:yellow;
}
<div class="register"></div>
<div class="FAQ"></div>
<div class="sponsors"></div>
<div class="footer"></div>

And if you add width:100% to the body it will get fixed:

* {
  margin: 0px;
  padding: 0px;
  border: 0px;
}

body {
  background-color: grey;
  width: 100%;
  height: 100%;
  position: absolute;
  margin: 0px;
  padding: 0px;
}

.register {
  display: table;
  width: 100%;
  min-height: 25%;
  background: red;
}

.FAQ {
  display: table;
  width: 100%;
  height: 25%;
  background: blue;
}

.sponsors {
  display: table;
  width: 100%;
  height: 25%;
  background: green;
}

.footer {
  display: table;
  width: 100%;
  height: 25%;
  background:yellow;
}
<div class="register"></div>
<div class="FAQ"></div>
<div class="sponsors"></div>
<div class="footer"></div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415