2016-04-21 5 views
0

Ich versuche, eine Website zu erstellen und ich habe Probleme, die Menüleiste über die Breite der Webseite zu strecken. Kann jemand bitte helfen? Hier ist meine CSS/HTML für die Menüleiste:Wie bekomme ich die Navigationsleiste über die gesamte Breite der Seite HTML CSS

ul { 
 
    list-style-type: none; 
 
    margin: 0px; 
 
    padding-left: 2px; 
 
    position: fixed; 
 
    top: 0px; 
 
    word-spacing: 2px; 
 
} 
 
li { 
 
    float: left; 
 
    display: inline; 
 
    word-spacing: 2px; 
 
    padding-left: 70px; 
 
    background-color: #610000; 
 
} 
 
#menubar a{ 
 
    display: inline; 
 
    text-align: center; 
 
    text-decoration: none; 
 
    font-size: 15px; 
 
    font-family: PT sans, sans-serif; 
 
    color: #FFDFC1; 
 
    padding-left:0px; \t 
 
} 
 

 

 
#menubar a:hover { 
 
    color: #092601; 
 
    background-color:#610000; 
 
} 
 
#menubar .active{ 
 
    color: #092601; 
 
} 
 

 
body{ 
 
    background-color: #ffffff; 
 
    margin-left: 350px; 
 
}
<div id="menubar"> 
 
    <ul> 
 
     <li><a href="home.html">Home</a></li> 
 
     <li><a href="about.html">About Us</a></li> 
 
     <li><a href="menu.html">Menu</a></li> 
 
     <li><a href="location.html">Location</a></li> 
 
     <li><a href="gallery.html">Gallery</a></li> 
 
     <li><a href="contact.html">Contact Us</a></li> 
 
    </ul> 
 
</div>

+2

Ihre HTML tatsächlich in der Frage gemacht, so dass wir sehr leicht den Code nicht sehen können. – fetherolfjd

+1

Bitte erstellen Sie ein jsfiddle oder Code-Snippet. – rmondesilva

+0

haben Sie versucht, Ihre #menubar 'width: 100%;'? – scoots

Antwort

1

li { 
 
    background-color: #610000; 
 
} 
 
#menubar a{ 
 
    text-decoration: none; 
 
    font-size: 15px; 
 
    font-family: PT sans, sans-serif; 
 
    color: #FFDFC1; 
 
} 
 
#menubar a:hover { 
 
    color: #092601; 
 
    background-color:#610000; 
 
} 
 
#menubar .active{ 
 
    color: #092601; 
 
} 
 
ul{ 
 
    padding: 0; 
 
    display: -webkit-box; 
 
    display: -moz-box; 
 
    display: box; 
 
} 
 
li{ 
 
    list-style: none; 
 
    list-style:none; 
 
    text-align: center; 
 
    -webkit-box-flex: 1; 
 
    -moz-box-flex: 1; 
 
    box-flex: 1; 
 
} 
 
body { 
 
    margin: 0px; 
 
}
<div id="menubar"> 
 

 
    <ul> 
 
       <li><a href="home.html">Home</a></li> 
 
       <li><a href="about.html">About Us</a></li> 
 
       <li><a href="menu.html">Menu</a></li> 
 
       <li><a href="location.html">Location</a></li> 
 
       <li><a href="gallery.html">Gallery</a></li> 
 
       <li><a href="contact.html">Contact Us</a></li> 
 
    </ul> 
 
</div>

+1

Vielen Dank für Ihre Antwort, aber es funktioniert immer noch nicht. Das verschiebt nur die gesamte Seite nach links. Während ich versuche, eine einzelne Seite Webseite zu erstellen, die den gesamten Bildschirm abdeckt und nur eine Scroll-Funktion ist. Aber ich kann die Menüleiste nicht über den gesamten oberen Rand der Seite ziehen. – CH26

+0

Entschuldigung, aktualisierte Antwort basiert auf http://stackoverflow.com/questions/7758866/making-an-unordered-list-span-100-the-width-of-a-div –

0

Um es relativ zu Ihrer Bildschirmgröße zu machen.

Verwenden Sie vw Einheit. So ist es zu passen, machen es 100vw auf ul ..

Dann in Ihrem li .. Entfernen Sie die padding-left there..and dann

eingestellt seine Breite als Breite der Mutter ul geteilt durch die Anzahl der Kinder li ..

width: calc(100%/6);

HINWEIS: calc() Funktion funktioniert nur auf modernen Browsern .. Sie es manuell wollen, wenn Sie einstellen können.

ul { 
 
     list-style-type: none; 
 
    \t margin: 0px; 
 
    \t padding-left: 2px; 
 
    \t position: fixed; 
 
    \t top: 0px; 
 
    \t word-spacing: 2px; 
 
     width: 100vw; 
 
    } 
 
    li { 
 
    \t float: left; 
 
     width: calc(100%/6); 
 
    \t display: inline; 
 
    \t word-spacing: 2px; 
 
    \t background-color: #610000; 
 
    } 
 
    #menubar { 
 
     width: 100%; 
 
    } 
 
    #menubar a{ 
 
    \t display: inline; 
 
    \t text-align: center; 
 
     text-decoration: none; 
 
    \t font-size: 15px; 
 
    \t font-family: PT sans, sans-serif; 
 
     color: #FFDFC1; 
 
     padding-left:0px; 
 
     
 
    \t 
 
    } 
 
    
 
    
 
    #menubar a:hover { 
 
     color: #092601; 
 
    \t background-color:#610000; 
 
    } 
 
    #menubar .active{ 
 
    \t color: #092601; 
 
    } 
 
    
 
    body{ 
 
    \t background-color: #ffffff; 
 
    }
<div id="menubar"> 
 

 
    <ul> 
 
    \t \t <li><a href="home.html">Home</a></li> 
 
    \t \t <li><a href="about.html">About Us</a></li> 
 
    \t \t <li><a href="menu.html">Menu</a></li> 
 
    \t \t <li><a href="location.html">Location</a></li> 
 
    \t \t <li><a href="gallery.html">Gallery</a></li> 
 
    \t \t <li><a href="contact.html">Contact Us</a></li> 
 
    </ul> 
 
</div>

0

1) Gib HTML und Körperbreite: 100%

2) Geben Sie die ul Breite: 100%

3) Entfernen des Körpers Rand

4) Geben Sie die Hintergrundfarbe statt li und Sie werden den Unterschied

bemerken

html, body { 
 
    width: 100%; 
 
    margin: 0; 
 
} 
 

 
body { 
 
    background-color: #ffffff; 
 
} 
 

 
ul { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    list-style: none; 
 
    margin: 0px; 
 
    padding-left: 2px; 
 
    word-spacing: 2px; 
 
    background-color: #610000; 
 
} 
 

 
li { 
 
    float: left; 
 
    word-spacing: 2px; 
 
    padding-left: 70px; 
 

 
} 
 

 
#menubar { 
 
    display: inline-block; 
 
    width: 100%; 
 
} 
 

 
#menubar a { 
 
    text-align: center; 
 
    text-decoration: none; 
 
    font-size: 15px; 
 
    font-family: PT sans, sans-serif; 
 
    color: #FFDFC1; 
 
    padding-left:0px; 
 
} 
 

 

 
#menubar a:hover { 
 
    color: #092601; 
 
    background-color: #610000; 
 
} 
 

 
#menubar .active{ 
 
    color: #092601; 
 
}
<ul id="menubar"> 
 
    <li><a href="home.html">Home</a></li> 
 
    <li><a href="about.html">About Us</a></li> 
 
    <li><a href="menu.html">Menu</a></li> 
 
    <li><a href="location.html">Location</a></li> 
 
    <li><a href="gallery.html">Gallery</a></li> 
 
    <li><a href="contact.html">Contact Us</a></li> 
 
    </ul>

https://jsfiddle.net/35c5b93q/

Verwandte Themen