Search code examples
htmlcssflexboxnavbar

Navigation Bar flexbox gaps on the sides


So, I'm having an issue with the margins on the sides of my navigation bar as there is a little gap that I don't want. To solve this I would make the margin equal to zero for all my elements by using the "*" in my CSS but I don't want my other elements to be affected.

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS Grid</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body style="background-color: #e3e3e3;">

    <main>
        <nav>
            <ul>
                <li><a href="#Owners">Owners</a></li>
                <li><a href="#Properties">Properties</a></li>
                <li><a href="#Property-Managers">Property-Managers</a></li>
                <li><a href="#Tenants">Tenants</a></li>
                <li><a href="#Maintanence">Maintanence</a></li>
            </ul>
        </nav>
    </main>
</body>
</html>

CSS:

* {
  margin: 0;
}
nav {
  padding-top: 350px;
}

nav ul {
  background-color: #181919;
  list-style: none;
  display: flex;
  flex-direction: row;
  justify-content: flex;
  padding: 15px;
  justify-content: center;
}
nav ul li a {
  text-decoration: none;
  color: white;
  padding: 0 30px;
}

Is there an alternate way for the margins for the navbar to be equal to 0 without affecting my other elements? I would greatly appreciate a solution for this!


Solution

  • You can use body{

    margin:0; }

    to get rid of extra space on the sides of your nav.