Sticky navbar

Par corentin philippe, il y a 9 ans


Les bases HTML/CSS

Bonjour,

Voila je rencontre un petit problème avec mon code.

Ce que je fais

Décrivez ici votre code ou ce que vous cherchez à faire
INDEX.HTML

<html> <head> <title>My Name</title> <meta charset="utf-8"> <link href="css/style.css" rel="stylesheet"> <link rel="stylesheet" href="css/bootstrap.css"> <!--- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> ---> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=BenchNine' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=Exo' rel='stylesheet' type='text/css'> <script type="text/javascript" src="js/bootstrap.js"></script> <!--- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> ---> </head> <body> <!-- bar de navigation --> <div class="nav-l"> <div class="nav__navbrand"> <div class="nav__navbrand--title">NAME OF <br> SITE</div> </div> <div class="nav__navbar"> <ul> <li><a class="nav__active" href="#">Accueil</a></li> <li><a href="#">Actus</a></li> <li><a href="#">Enseignement</a></li> <li><a href="#">Administration</a></li> <li><a href="#">Partenaire et liens utiles</a></li> <li><a href="#">Contact</a></li> </ul> </div> </div> <div class="home-l container"> <div class="baseline-l"> Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator. <br><br><br> <a href="#" class="btn-circle"> <i class="fa fa-angle-double-down animated"></i> </a> </div> </div> </body> </html>

STYLE.CSS

/* BASE */ body { background: url("../img/background.jpg") center top fixed; background-size: cover; } .center { text-align: center; } /* BTN */ .btn-circle:hover { color: #fff; background: rgba(255, 255, 255, .1); outline: 0; } .btn-circle i.animated { -webkit-transition-duration: 1s; -moz-transition-duration: 1s; -webkit-transition-property: -webkit-transform; -moz-transition-property: -moz-transform; } .btn-circle:hover i.animated { -webkit-animation-name: pulse; -moz-animation-name: pulse; -webkit-animation-duration: 1.5s; -moz-animation-duration: 1.5s; -webkit-animation-timing-function: linear; -moz-animation-timing-function: linear; -webkit-animation-iteration-count: infinite; -moz-animation-iteration-count: infinite; } @-webkit-keyframes pulse { 0,100% { -webkit-transform: scale(1); transform: scale(1); }50% { -webkit-transform: scale(1.2); transform: scale(1.2); } } @-moz-keyframes pulse { 0,100% { -moz-transform: scale(1); transform: scale(1); }50% { -moz-transform: scale(1.2); transform: scale(1.2); } } .btn-circle { width: 70px; height: 70px; padding: 7px 16px; margin-top: 15px; font-size: 40px; color: #c4c3c5; background: transparent none repeat scroll 0 0; border: 2px solid #c4c3c5; border-radius: 100% !important; transition: #74a402 .3s ease-in-out 0s; } /* NAV */ .nav-l { margin-top: 7%; } .nav__navbrand { top: 0; right: 0; left: 0; z-index: 99999; width: 100%; height: 118px; font-family: BenchNine, sans-serif; background-color: rgba(0, 0, 0, .65); border-top: 1px solid rgba(108, 108, 108, .3); border-bottom: 1px solid rgba(108, 108, 108, .3); } .nav__navbrand--title { padding-top: 7px; font-size: 40px; font-weight: 500; color: #c4c3c5; text-align: center; letter-spacing: 3px; } .nav__navbar { width: 63%; margin-right: auto; margin-left: auto; background-color: rgba(0, 0, 0, .46); } .nav__navbar > ul > li { display: inline; padding: 5px; font-size: 16px; font-weight: bold; letter-spacing: .8px; } .nav__navbar > ul { margin-bottom: 10px; margin-left: -39px; text-align: center; } .nav__navbar > ul > li > a { font-family: Exo,sans-serif; color: #b1afaf; } .nav__navbar > ul > li > a:hover, .nav__navbar > ul > li > a:focus { font-family: Exo,sans-serif; color: #dbdbdb; text-decoration: none; } /* BASELINE */ .baseline-l { width: 76%; padding-top: 100px; margin-right: auto; margin-left: auto; font-size: 28px; font-weight: 600; color: #e2e1e3; text-align: center; }

Ce que je veux

Je voudrais que la navbar se colle au top une fois la page déssendu. quelle ce colle....

4 réponses

Benjamin Derepas, il y a 9 ans

Tu dois passer par du javascript (ou : position:sticky mais supporté uniquement par firefox

corentin philippe, il y a 9 ans

je sais mais moi et le js ......

Benjamin Derepas, il y a 9 ans

Tu dois tout d'abbord écouter l'évènement sur le document (le body en l'occurance).
Ensuite tu détect la position du scroll par rapport au haut du document .
Voilà , après je te laisse chercher ça sur internet tu trouvera facilement.
C'est très simple à faire, même pas besoin de jQuery .

corentin philippe, il y a 9 ans

merci mais je ne fait quasiment pas de js