Tim Yanmaz
Tim Yanmaz

Reputation: 21

How to make a navbar on a row with HTML and CSS?

My ul elements doesn't go on top of the header. I tried to use position absolute and relative but then it's messing up. ul should go on the background. Is it because of the logo? I just want a basic navbar. Please anyone that can help?


    @import url("https://fonts.googleapis.com/css2?family=Nunito:wght@800&display=swap");
    @import url("https://fonts.googleapis.com/css2?family=Fruktur&family=Nunito:wght@800&display=swap");
    
    * {
      margin: 0;
      padding: 0;
      color: white;
      list-style: none;
      text-decoration: none;
      box-sizing: border-box;
      font-family: "Nunito", sans-serif;
    }
    
    header {
      width: 100%;
      height: 60px;
      background-color: #141517;
    
      .Logo {
        width: 120px;
        margin-top: 15px;
        margin-left: 8px;
      }
    
      ul {
        text-align: center;
      }
    
      li {
        font-size: 15px;
        margin: 0 10px;
        line-height: 60px;
        display: inline-block;
      }
    }

Example with CSS

@import url("https://fonts.googleapis.com/css2?family=Nunito:wght@800&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Fruktur&family=Nunito:wght@800&display=swap");
* {
  margin: 0;
  padding: 0;
  color: white;
  list-style: none;
  text-decoration: none;
  box-sizing: border-box;
  font-family: "Nunito", sans-serif;
}

header {
  width: 100%;
  height: 60px;
  background-color: #141517;
}

header .Logo {
  width: 120px;
  margin-top: 15px;
  margin-left: 8px;
}

header ul {
  text-align: center;
}

header li {
  font-size: 15px;
  margin: 0 10px;
  line-height: 60px;
  display: inline-block;
}
<script src="https://kit.fontawesome.com/7ddb0129cc.js" crossorigin="anonymous"></script>

<body style="background-color: #202020">
  <header>
    <img class="Logo" src="Logo.svg" />
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">Developing</a></li>
      <li><a href="#">LeaderBoards</a></li>
    </ul>
  </header>

Upvotes: 1

Views: 2249

Answers (1)

Youssouf Oumar
Youssouf Oumar

Reputation: 45883

You could use flexbox or grid, the modern two ways in CSS to create layouts. I used flexbox below to make it work. I also used css instead of scss juste to have it work here on Stack Overflow.

@import url("https://fonts.googleapis.com/css2?family=Nunito:wght@800&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Fruktur&family=Nunito:wght@800&display=swap");

* {
  margin: 0;
  padding: 0;
  color: white;
  list-style: none;
  text-decoration: none;
  box-sizing: border-box;
  font-family: "Nunito", sans-serif;
}

header {
  width: 100%;
  min-height: 60px;
  background-color: #141517;
  display:flex;
  align-items:center;
  justify-content : space-between;
}

 .Logo {
    width: 120px;
    margin-top: 15px;
    margin-left: 8px;
  }

  ul {
    text-align: center;
    display: flex;
  }

  li {
    font-size: 15px;
    margin: 0 10px;
    line-height: 60px;
    display: inline-block;
  }
<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>RoPoop</title>
  <link rel="shortcut icon" type="image/jpg" href="favicon.ico" />
  <link rel="stylesheet" href="CSS/IndexStyle.css" />
  <script src="https://kit.fontawesome.com/7ddb0129cc.js" crossorigin="anonymous"></script>
</head>

<body style="background-color: #202020">
  <header>
    <img class="Logo" src="Logo.svg" />
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">Developing</a></li>
      <li><a href="#">LeaderBoards</a></li>
    </ul>
  </header>
</body>

</html>

Upvotes: 1

Related Questions