AMRJO AMRJO - 1 month ago 9
CSS Question

Div Element act like a background

how can I make a element act like a background like the intro of this web jabarprov.go.id?

This is my codepen
http://codepen.io/anon/pen/RGEmxB

Here is my source code

<div id="div1" class="col-md-3">LEFT SECTION</div>
<div id="div2" class="col-md-9">RIGHT SECTION</div>
<nav class="main-bg">
<div class="container">
NAVIGATION HERE
</div>
</nav>
<section id="screen2"></section>
<section id="screen3"></section>


and My CSS:

#div1, #div2{
height:100vh;
}

#div1{background-color:cyan}
#div2{background-color:lightgrey}

nav {
position: absolute;
bottom: 0;
width: 100%;
background: Green;
padding:2px 0;
z-index:1;
}

.fixed {
position: fixed;
top: 0;
height: 70px;
z-index: 1;
}
section {
height: 100vh;
}

/* Screens Settings */
#screen1 {
background: #43b29d;
}

#screen1 p {
padding-top: 200px;
}

#screen2 {
background: #efc94d;
}


and my script (using jquery)

$(document).ready(function(){
$(window).bind('scroll', function() {
var navHeight = $( window ).height() - 70;
if ($(window).scrollTop() > navHeight) {
$('nav').addClass('fixed');
}
else {
$('nav').removeClass('fixed');
}
});
});


The problem is the intro my page is not fixed (acts like fixed background). Thanku before.

Sorry for my english.

Answer

I modified your code. Hope it is what you searched for http://codepen.io/anon/pen/qaLGrp

I made a wrapper around div1 and 2 which is fixed and made change to sizes

wrapper

<div id="intro-wrapper">
  <div id="div1" class="col-md-3">a</div>
  <div id="div2" class="col-md-9">b</div>
</div>

wrapper css and sizes

body{
  padding-top: 100vh;
}
#intro-wrapper{
  z-index: -1;
  position: fixed;
  top: 0;
  width: 100vw;
}
#div1, #div2{
  height:calc(100vh - 70px);
}

navigation position

nav {
  position: absolute;
  top: calc(100vh - 70px);
  width: 100%;
  background: Green;
  padding:2px 0;
  z-index:1;
  height:70px;
}