0

I'm a beginner. I tried to build a navbar with flex but failed to get the desired result. what I want is

Logo Home About Services Contact

* {
  margin: 0;
  padding: 0;
  font-family: monospace;
}

.nav {
  display: flex;
  background-color: gray;
}

.menu {
  list-style: none;
  display: inline-block;
  padding: 20px
}

a {
  text-decoration: none;
}

.con {
  float: right;
}
<header class="nav">
  <img src="./Logo.png" width="80px" class="logo" alt="">
  <nav>
    <ul>
      <li id="home" class="menu"><a href="">Home</a> </li>
      <li id="about" class="menu"><a href="">About</a> </li>
      <li id="services" class="menu"><a href="">Services</a> </li>
      <li id="contact" class="menu con"><a href="">Contact</a> </li>
    </ul>
  </nav>
</header>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
Shahbaz
  • 3
  • 2

2 Answers2

0

You can use display flex and justify-content property to move items.

.nav
{
  width:100%;
  display:flex;
  justify-content:space-evenly;
  align-items:center
}
.img-wrapper
{
  width:33.33%;
}
.nav-items-center
{
  width:33.33%;
  display:flex;
  justify-content:space-evenly;
  align-items:center;
}
.nav-item-right
{
  width:33.33%;
  display:flex;
  justify-content:space-evenly;
  align-items:center;
}
<header class="nav">
    <div class="img-wrapper">
     <img src="./Logo.png" width="80px" class="logo" alt="Logo">
    </div>
    <ul class="nav-items-center">
      <li id="home" class="menu"><a href="">Home</a> </li>
      <li id="about" class="menu"><a href="">About</a> </li>
      <li id="services" class="menu"><a href="">Services</a> </li>
    </ul>
    <ul class="nav-item-right">
      <li id="contact" class="menu con"><a href="">Contact</a> </li>
    </ul>
</header>
Ferin Patel
  • 3,424
  • 2
  • 17
  • 49
0

* {
  margin: 0;
  padding: 0;
  font-family: monospace;
}

.header {
  display: flex;
  background-color: gray;
  width: 100%;
}

nav {
  width: 100%;
}

ul {
  display: flex;
  justify-content: space-between;
}

.menu {
  list-style: none;
  display: inline-block;
  padding: 20px
}

a {
  text-decoration: none;
}

.con {
  float: right;
}
<header class="header">  
  <nav>    
    <ul>
      <img src="./Logo.png" width="80px" class="logo" alt="">
      <div>
        <li id="home" class="menu"><a href="">Home</a> </li>
        <li id="about" class="menu"><a href="">About</a> </li>
        <li id="services" class="menu"><a href="">Services</a> </li>
      </div>
      <li id="contact" class="menu con"><a href="">Contact</a> </li>
    </ul>
  </nav>
</header>

I believe this is what you are looking for

Sen Alexandru
  • 1,953
  • 3
  • 19
  • 35