Menu does not stick underneath the header

Asked

Viewed 286 times

0

I have a video on html5 at the beginning of the page and then a menu below it that should be fixed as we scroll the page as in this website here.

However I do not know what the correct way to do this, remembering that this has to work in all browsers including Internet Explorer:

Here is my code:

@import url(http://fonts.googleapis.com/css?family=Dancing+Script);
@import url(http://fonts.googleapis.com/css?family=Scada);
@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro);
 html,
body {
  margin: 0;
  padding: 0;
}
a {
  text-decoration: none;
  outline: none;
}
button {
  cursor: pointer;
  outline: none;
}
ul li {
  list-style-type: none;
}
header {
  position: relative;
  top: 0;
  overflow: hidden;
  width: 100%;
  height: 90%;
  min-height: 800px;
}
video {
  height: 710.4375px;
  width: 100%;
  z-index: -1;
  position: absolute;
  top: 0;
  left: 0;
  -webkit-transform: scaley(1.72);
  -o-transform: scaley(1.72);
  -ms-transform: scaley(1.72);
  -moz-transform: scaley(1.72);
  transform: scaley(1.72);
  z-index: -2;
}
#bg-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(../images/overlay.png);
  z-index: -1
}
.texto-header {
  position: absolute;
  top: 30%;
  left: 50%;
  margin-left: -280px;
  width: 600px;
  text-align: center;
  z-index: 2;
  color: #FFF;
}
.texto-header h1 {
  font-family: 'Dancing Script', cursive;
  font-size: 3.5em;
}
.texto-header p {
  /*font-family: 'Scada', sans-serif;*/
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 1em;
  line-height: 20px;
}
.texto-header button {
  color: #fff;
  background: transparent;
  border: 2px solid #fff;
  width: 220px;
  height: 50px;
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 1.2em;
  border-radius: 5px;
  margin-top: 5%;
}
.texto-header button:hover {
  color: #000;
  background-color: #fff;
}
.menu-header {
  margin-top: 0px;
  position: absolute;
  top: auto;
  bottom: 0px;
  background-color: lime;
  width: 100%;
  height: 100px;
}
.menu {
  margin: 40px auto;
  text-align: center;
}
.menu li {
  display: inline;
}
.menu li a {
  margin: 15px;
}
<header>
  <div id="video">
    <video id="Video1" id="bgvid" autoplay loop>
      <source src="video/animacao-lol.mp4" type="video/mp4" />desculpe mais seu navegador não suporta este formato ou esta desatualizado :(
    </video>
  </div>
  <div id="bg-video"></div>

  <div class="texto-header">
    <h1>Olá amigos somos a <strong>Tec Mov!</strong></h1>
    <p>dolor sit amet, consectetur adipiscing elit. Sed at risus neque.
      <br>Cras sit amet ligula ut justo commodo porta id ut enim. Nulla est lectus, mollis sit amet vehicula id, volutpat eget mauris.</p>
    <button>Vamos Começar ?</button>
  </div>

</header>

<nav class="menu-header">
  <ul class="menu">
    <li><a href="">Home</a>
    </li>
    <li><a href="sobre.html">Sobre</a>
    </li>
    <li><a href="games.html">Games</a>
    </li>
    <li><a href="eventos.html">Eventos</a>
    </li>
    <li><a href="team.html">Team</a>
    </li>
    <li><a href="contato.php">Contato</a>
    </li>
    <li><a href="">Noticias</a>
    </li>
    <li><a href="http://www.novaerateam.com.br/forum/" target="_blank">Forum</a>
    </li>
  </ul>
</nav>

1 answer

1


There are some mistakes and improvements that should be made in your code, such as not using two ids in the same div:

<video id="Video1" id="bgvid" autoplay loop>

Here you should wear only one id and a class, or apply the styles of the second id to the video1 so that you only get one id. Example using a id and a class:

<video id="Video1" class="bgvid" autoplay loop>

But I spent a little bit of time here and I reworked all of your code in full and also added a responsive video to the first section in the right way:

$(document).scroll(function() {
    var navHeight = $( window ).height() - 70;
    if ($(window).scrollTop() > navHeight) {
        $('nav').addClass('fixed');
    }
    else {
        $('nav').removeClass('fixed');
    }
});
/* Este CSS faz o video preencher a 100% o seu Recipiente */
.videoRecipiente {
    height:100%;
    overflow: hidden;
}
.videoRecipiente video {
    min-width: 100%;
    min-height: 100%;
}
.textoSobreVideo {
    color: #fff;
    position: absolute;
    bottom: 60px;
    text-align: center;
    width: 100%;
}

/* Esta class é adicionada ao fazer - scroll */
.fixed {
    position: fixed; 
    top: 0; 
    height: 70px; 
    z-index: 1;
}
body {
    color: #fff;
    font-family: 'open-sans-bold'; 
    font-size: 18px;
    text-align: center;
}
section {
    height: 88vh;
}

/* Navegação */
nav {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 70px;
    background: #fff;
}
nav ul {
    margin: 0;
    padding: 0;
}
nav li {
    display: inline-block;
    padding: 24px 10px;
}
nav li a {
    color: #757575;
    text-transform: uppercase;
}

/* Seccões */
#screen1 {	
    background: #43b29d;
}
#screen2 {
    background: #efc94d;
}
#screen3 {
    background: #e1793d;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

<section id="screen1">
    <div class="videoRecipiente">
        <video autoplay loop muted>
            <source src="http://www.w3schools.com/html/mov_bbb.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
            <source src="http://www.w3schools.com/html/mov_bbb.mp4" type='video/webm; codecs="vp8, vorbis"' />
                Este video não é suportado pelo seu navegador.
            </video>
            <div class="textoSobreVideo">
                <p>Olá amigos somos a <strong>Tec Mov!</strong></p>
            </div>
    </div>
	<nav>
        <ul>
            <li><a href="#">Início</a></li>
            <li><a href="#">Sobre</a></li>
            <li><a href="#">Games</a></li>
            <li><a href="#">Eventos</a></li>
            <li><a href="#">Contactos</a></li>
        </ul>
	</nav>
</section>
	
<section id="screen2"></section>
<section id="screen3"></section>

Has in attention that the jQuery bookstore should be implemented preference within the tag <head> of your site and not somewhere in the middle of your <body>, this was just an example for that the code worked correctly.

Example:

<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</head>

Here’s also an example in jsFiddle http://jsfiddle.net/ns2p2m6w of the above code and also another version of the menu, which only appears when you scroll up http://jsfiddle.net/xc9jxu7u

  • vlw friend our I had not seen that I put two id’s oloko suhausha thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.