• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

CSS I cannot get these elements to align in my nav

Liljeqvist

New Coder
I am having an issue with my navigation menu.
I use flexbox to align all the items, but for some reason I cannot get the logo / brand name to line up wtith the burger-icon.
I added space-between to the parent container, because I want the logo on the left side, and the menu-icon on the right side,
but instead the icon appears underneath the logo.


css.png


What did I miss in my stylesheet?

HTML:
  <nav class="navbar">
    <div class="mobile-top-container">
      <div class="company-name">
        <h1>
          <router-link style="color: #ffffff" :to="{ name: 'Home' }"
            >Brand</router-link
          >
        </h1>
      </div>
      <div class="navigation-icon" @click="toggleNav">
        <i class="pi pi-bars"></i>
      </div>
    </div>
    <div class="navbar-links">
      <ul>
        <li>
          <router-link style="color: #ffffff" :to="{ name: 'Menukort' }"
            >Menukort</router-link
          >
        </li>
        <li>Bordbestilling</li>
        <li>
          <router-link style="color: #ffffff" :to="{ name: 'Hotel' }"
            >Hotellet</router-link
          >
        </li>
        <li>
          <router-link style="color: #ffffff" :to="{ name: 'Selskaber' }"
            >Selskaber</router-link
          >
        </li>
        <li>Kontakt</li>
      </ul>
    </div>
  </nav>

CSS:
<style scoped>
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 10px;
  background-color: #2f3745;
  text-decoration: none;
  color: #ffffff;
}

.company-name {
  margin-left: 20px;
}
nav ul {
  display: flex;
  margin: 0;
  padding: 0;
}
nav ul li {
  display: block;
  list-style: none;
  color: #ffffff;
  padding: 20px;
  font-size: 1em;
}
nav ul li:hover {
  background-color: #555555;
}
.navigation-icon {
  padding: 10px;
  cursor: pointer;
  margin-right: 20px;
  display: none;
}
.pi-bars {
  font-size: 30px;
  color: #fff;
}
.mobile-top-container {
  justify-content: space-between;
}

@media (max-width: 800px) {
  .navbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .navigation-icon {
    display: flex;
  }
  .navbar-links {
    display: none;
    width: 100%;
    transition: all 0.5s;
  }
  .navbar-links ul {
    flex-direction: column;
    width: 100%;
    transition: all 0.5s;
  }
  .navbar-links li {
    text-align: center;
  }
  .navbar-links.active {
    display: flex;
    transition: all 0.5s;
  }
}
</style>
 

simong1993

Active Coder
Staff Team
Guardian
Although i cannot recreate the error you have but what i can suggest is a more simple way of doing what you are trying to do :D, Easier is always better :D

HTML:
<html>
  <head>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
    </head>
    <body>

      <div class="container">
        <header class="d-flex flex-wrap justify-content-center py-3 mb-4 border-bottom">
          <a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none">
            <svg class="bi me-2" width="40" height="32"><use xlink:href="#bootstrap"></use></svg>
            <span class="fs-4">Simple header</span>
          </a>

          <ul class="nav nav-pills">
            <li class="nav-item"><a href="#" class="nav-link active">Home</a></li>
            <li class="nav-item"><a href="#" class="nav-link">Features</a></li>
            <li class="nav-item"><a href="#" class="nav-link">Pricing</a></li>
            <li class="nav-item"><a href="#" class="nav-link">FAQs</a></li>
            <li class="nav-item"><a href="#" class="nav-link">About</a></li>
          </ul>
        </header>
      </div>
    </body>
</html>

The code above is a template design of what you where doing, no style sheet needed as it comes from bootstrap. With the code above you just need to change the colours and text and away you go and you can also do drop menus. Let me know if you need any help with bootstrap or we can try and recreate the error you are getting :)
 

Top