简体   繁体   中英

How can I make a navigation bar fill up the whole width of the screen?

I've been trying to make a navbar, but even when I set the width to 100%, it doesn't take up the width. I attached my code here.

 ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #333; position: fixed; top: 0; width: 100%; } li { display: inline; float: left; } li a { display: block; color: black; text-align: center; padding: 14px 16px; text-decoration: none; } #nav { display: block; padding: 8px; background-color: #dddddd; }
 <ul> <li><a href="index.html" id="nav">Home</a></li> <li><a href="Generator.html" id="nav">Generator</a></li> <li><a href="contact.html" id="nav">Contact</a></li> <li><a href="about.html" id="nav">About</a></li> </ul>

Remove the default margin on the body or add left:0 to your ul rules:

 ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #333; position: fixed; top: 0; width: 100%; } li { display: inline; float: left; } li a { display: block; color: black; text-align: center; padding: 14px 16px; text-decoration: none; } #nav { display: block; padding: 8px; background-color: #dddddd; } body {margin:0;}
 <ul> <li><a href="index.html" id="nav">Home</a></li> <li><a href="Generator.html" id="nav">Generator</a></li> <li><a href="contact.html" id="nav">Contact</a></li> <li><a href="about.html" id="nav">About</a></li> </ul>

 *{ box-sizing: border-box; margin: 0; padding:0; } ul{ width: 100vw; height: 10vw; background-color: #003580; display: flex; justify-content:flex-end; align-items: center; } ul li{ background-color: #dddd; border-radius: 3px; padding: 0 2px; margin-right: 10px; list-style: none; }.nav{ color: black; text-decoration: none; font-size: 25px; }
 <.DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>Barra de navegación</title> <link rel="stylesheet" href="./stylos.css"> </head> <body> <header> <ul> <li><a href="index.html" class="nav">Home</a></li> <li><a href="Generator.html" class="nav">Generator</a></li> <li><a href="contact.html" class="nav">Contact</a></li> <li><a href="about.html" class="nav">About</a></li> </ul> </header> </body> </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM