2017-02-04 6 views
0

Hallo Leute Ich lerne Bootstrap, indem Sie eine persönliche Webseite. Ich habe eine Navigationsleiste mit der Affix-Option erstellt, aber beim Scrollen nach unten scheint der rechte Rand gebrochen zu sein. Kannst du mir helfen, herauszufinden, warum? Vielen Dank im Voraus, hier ist der Code:Bootstrap 'Affix' auf Navbar bricht den rechten Rand

<!DOCTYPE html> 
 
<html lang="en"> 
 

 
<head> 
 
    <meta charset="UTF-8"> 
 
    <meta name="viewport" content="width:device-width, initial-scale = 1"> 
 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 
    <style> 
 
    .affix { 
 
     top: 0; 
 
     width: 100%; 
 
    } 
 
    .affix + .container-fluid { 
 
     padding-top: 70px; 
 
    } 
 
    </style> 
 
</head> 
 

 
<body> 
 
    <div class="container-fluid"> 
 
    <div class="alert alert-warning alert-dismissable fade in"> 
 
     <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a> 
 
     <strong>Warning!</strong> This site uses cookies 
 
    </div> 
 
    <nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="197"> 
 
     <div class="container-fluid"> 
 
     <div class="navbar-header"> 
 
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> 
 
      <span class="icon-bar"></span> 
 
      <span class="icon-bar"></span> 
 
      <span class="icon-bar"></span> 
 
      </button> 
 
      <a class="navbar-brand" href="#">Something</a> 
 
     </div> 
 
     <div class="collapse navbar-collapse" id="myNavbar"> 
 
      <ul class="nav navbar-nav"> 
 
      <li><a href="#">Home</a> 
 
      </li> 
 
      <li><a href="#">Pag 1</a> 
 
      </li> 
 
      <li><a href="#">Pag 2</a> 
 
      </li> 
 
      </ul> 
 
      <ul class="nav navbar-nav navbar-right"> 
 
      <li> 
 
       <a href="#"> <span class="glyphicon glyphicon-log-in"> </span> 
 
       </a> 
 
      </li> 
 
      </ul> 
 

 
     </div> 
 
     </div> 
 
    </div> 
 
    <div class="container-fluid" style="height:1000px"> 
 
    <h1>Some text to enable scrolling</h1> 
 
    <h1>Some text to enable scrolling</h1> 
 
    <h1>Some text to enable scrolling</h1> 
 
    <h1>Some text to enable scrolling</h1> 
 
    <h1>Some text to enable scrolling</h1> 
 
    <h1>Some text to enable scrolling</h1> 
 
    <h1>Some text to enable scrolling</h1> 
 
    <h1>Some text to enable scrolling</h1> 
 
    <h1>Some text to enable scrolling</h1> 
 
    <h1>Some text to enable scrolling</h1> 
 
    <h1>Some text to enable scrolling</h1> 
 
    </div> 
 
</body> 
 

 
</html>

Edit: Mit Chrom Inspektor i eine Warnung gefunden habe. Es heißt: "Die Schlüsselbreite": Gerätebreite "wird nicht erkannt und ignoriert."

Antwort

0

Sie verpassen einige schließende Tags. Ich hoffe, dass das folgende Snippet Ihnen hilft.

<!DOCTYPE html> 
 
<html lang="en"> 
 
    
 
    <head> 
 
     <meta charset="UTF-8"> 
 
     <meta name="viewport" content="width:device-width, initial-scale = 1"> 
 
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
 
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 
    </head> 
 

 
    <body> 
 
     <nav class="navbar navbar-inverse navbar-fixed-top" data-spy="affix" data-offset-top="197"> 
 
      <div class="container-fluid"> 
 
       <div class="navbar-header"> 
 
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> 
 
         <span class="icon-bar"></span> 
 
         <span class="icon-bar"></span> 
 
         <span class="icon-bar"></span> 
 
        </button> 
 
        <a class="navbar-brand" href="#">Something</a> 
 
       </div> 
 
       <div class="collapse navbar-collapse" id="myNavbar"> 
 
        <ul class="nav navbar-nav"> 
 
         <li><a href="#">Home</a></li> 
 
         <li><a href="#">Pag 1</a></li> 
 
         <li><a href="#">Pag 2</a></li> 
 
        </ul> 
 
        <ul class="nav navbar-nav navbar-right"> 
 
         <li> 
 
          <a href="#"><span class="glyphicon glyphicon-log-in"/></a> 
 
         </li> 
 
        </ul> 
 
       </div> 
 
      </div> 
 
     </nav> 
 
     <div class="container-fluid"> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
      <h1>Some text to enable scrolling</h1> 
 
     </div> 
 
    </body> 
 
</html>

+0

Vielen Dank für die schnelle Antwort! Das funktioniert für mich, aber ich versuche einen Weg zu finden, die "Navbar-Fixed-Top" -Klasse in der Navbar-Deklaration wegzulassen, weil ich nicht so sehr mag, wie es aussieht. – Pasq

+0

Mir ist auch aufgefallen, dass das Nav mit dem Navbar-Fixed-Top meinen Beispieltext abdeckt, also ist es nicht die Lösung, die ich suche. – Pasq

Verwandte Themen