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

Time:08-31

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>

CodePudding user response:

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>

  • Related