2

I'm working on a homepage with multiple sections.

<div id="section1">
    <!-- This needs to be the full height of the screen -->
</div>
<div id="section2">

</div>
<div id="section3">

</div>

I would like section1 to be the full height of the screen and then the user can scroll down to see section2 and section3 - can this be done with CSS alone or will I need JS to set this dynamically?

tommyd456
  • 10,443
  • 26
  • 89
  • 163

4 Answers4

2

You can use viewport units

CSS

#section1{
    display: block;
    background: #000;
    width: 100vw;
    height: 100vh;
}

DEMO HERE

Luís P. A.
  • 9,524
  • 2
  • 23
  • 36
0

No need for JavaScript here. With with simple css you can do it easily:

#section1{
    width:100%;
    height:100%;
    display:block; // or inline-block - Optional
}

You may have to set the body & html tags height:100% too, but not always.

divoom12
  • 802
  • 4
  • 12
0

You can try like this-

    html, body{height: 100%;}
    #section1{background: red;min-height:100%;}
<div id="section1">
   s <!-- This needs to be the full height of the screen -->
</div>
<div id="section2">

</div>
<div id="section3">

</div>
Mukul Kant
  • 7,074
  • 5
  • 38
  • 53
0
$(document).scroll(function() {
  var y = $(this).scrollTop();
  if (y > 800) {
    $('.bottomMenu').fadeIn();
  } else {
    $('.bottomMenu').fadeOut();
  }
});

From here

Community
  • 1
  • 1
Vitalina
  • 51
  • 9