Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make section fullscreen of current screen

Tags:

html

css

I have five section:

<section id="one">Page 1</section>
<section id="two">Page 2</section>
<section id="three">Page 3</section>
<section id="four">Page 4</section>
<section id="five">Page 5</section>

And I want to make each of them fullscreen of current screen (i have screen 1920/1080 other has 1024/768 etc)

I have css code like this:

section {
display: block;
background: #CFF;
height:2000px;
padding: 60px;
padding-left: 120px;
}

when I'm chanching height from 2000px to 100% result is that: enter image description here

any idea how can i solve this problem?

JSFIDDLE

EDIT

I've found nice article about that. see here if anyone will need it

like image 807
gsiradze Avatar asked Aug 11 '14 14:08

gsiradze


4 Answers

You need to implicitly set the dimensions of the document (body) to those of the viewport (html), then give a height and width of 100% to each section- which is then calculated relative to this.

Change your CSS for body and section to:

Demo Fiddle

html, body {
    margin: 0;
    height:100%;
    width:100%;
    padding:0;
}

section {
    display: block;
    background: #CFF;
    height:100%;
    width:100%;
    padding: 60px;
    padding-left: 120px;
    box-sizing:border-box;
}

By adding box-sizing:border-box; to the CSS for section, each section will maintain 100% width inclusive of the applied padding.

Note

You can also viewport percentage units, namely use vh and vw (viewport height) and (viewport width) units to cause content to stretch to fill a proportionate amount of the viewport, where 100 = 100%. This is likely the preferred solution vs implicit % units, depending on your required browser support and does not require the element to be nested within a parent with explicit height/width settings

like image 87
SW4 Avatar answered Sep 30 '22 15:09

SW4


Just use:

section {
    height:100vh;
    width: 100vw;
}

No need to set height and width properties for <body> and <html> tags.

like image 36
nyxz Avatar answered Sep 30 '22 15:09

nyxz


Set the height on the body and html elements to 100%, then use height:100% on the sections.

html, body {
    height:100%;
}

jsFiddle example

like image 30
j08691 Avatar answered Sep 30 '22 14:09

j08691


You need to set the document's height to the size of the browser viewport before you can give it's children a height in percents:

body, html {
    margin: 0;
    height:100%
}

Then, just give the sections a height of 100%:

section {
    display: block;
    background: #CFF;
    height:100%;
    padding: 60px;
    padding-left: 120px;
}

JSFiddle Demo

like image 21
Jacob Gray Avatar answered Sep 30 '22 15:09

Jacob Gray