skip to Main Content

I have a Menu toggle icon in top Navbar which is refusing to float left.

header {
  position: fixed;
  right: 0;
  top: 0;
  left: 0;
  z-index: 100;
  height: 60px;
  box-shadow: 0px 5px 5px -5px rgb(0 0 0 /10%);
  background-color: #2980b9;
  transition: left 300ms;
}

.header-content {
  display: flex;
  align-items: center;
  height: 100%;
  /* justify-content: space-between; */
}

.dropdown {
  display: flex;
  position: relative;
  align-items: center;
  justify-content: right;
  padding: 4px;
  margin: 0px 15px;
  width: 100%;
  border: 1px solid #5499c7;
}

.dropdown a,
label {
  color: #fff;
  position: relative;
  Padding: 2px 4px;
  background: #5499c7;
}

.dropdown a {
  font-size: 1.6rem;
  margin-left: 1.4rem;
  border-radius: 50%;
}

.dropdown label {
  font-size: 1.6rem;
  text-align: left;
  margin: 0rem;
  cursor: pointer;
  float: left;
}
<link rel="stylesheet" href="https://maxst.icons8.com/vue-static/landings/line-awesome/line-awesome/1.3.0/css/line-awesome.min.css">
<header>
  <div class="header-content">
    <div class="dropdown">
      <label for="menu-toggle">
                <span class="las la-bars"></span>
            </label>

      <a href="#">
        <span class="las la-home"></span>
      </a>

      <a href="#">
        <span class="las la-envelope"></span>
      </a>

      <a href="#">
        <span class="las la-bell"></span>
      </a>

      <a href="#">
        <span class="las la-user"></span>
      </a>

    </div>
  </div>
</header>

As you can see the picture below: (marked red arrow line)

Top navbar

I want all Navbar items float right except toggle-menu icon bar which is span Anyone can help i appreciate.

I tried floating left, but it refuses

3

Answers


  1. Have a lot of solutions to do it, this is a suggestion:

    CSS

    .dropdown {
        display: flex;
        position: relative;
        align-items: center;
        justify-content: space-between; // <- added this
        padding: 4px;
        margin: 0px 15px;
        width: 100%;
        border: 1px solid #5499c7 ;
    }
    

    HTML

    <div class="dropdown">
        <label for="menu-toggle">
            <span class="las la-bars"></span>
        </label>
    
        <div><!--Wrapped your menu link in a div-->
            <a href="#" >
                <span class="las la-home" ></span>
            </a>
    
            <a href="#" >
                <span class="las la-envelope" ></span>
            </a>
    
            <a href="#" >
                <span class="las la-bell" ></span>
            </a>
    
            <a href="#" >
                <span class="las la-user" ></span>
            </a>
        </div>
    
    </div>
    
    Login or Signup to reply.
  2. You can add flex-gorw:1; on toggle btn.

    .dropdown > *:first-child {
      flex-grow: 1;
    }
    

    Because you hava background color on label, I wrap label by span so the transparent span will fill the space.

    <span>
        <label for="menu-toggle">
            <span class="las la-bars"></span>
        </label>
    </span>
    
    header {
      position: fixed;
      right: 0;
      top: 0;
      left: 0;
      z-index: 100;
      height: 60px;
      box-shadow: 0px 5px 5px -5px rgb(0 0 0 /10%);
      background-color: #2980b9;
      transition: left 300ms;
    }
    
    .header-content {
      display: flex;
      align-items: center;
      height: 100%;
    }
    
    .dropdown {
      display: flex;
      position: relative;
      align-items: center;
      justify-content: right;
      padding: 4px;
      margin: 0px 15px;
      width: 100%;
      border: 1px solid #5499c7;
    }
    
    .dropdown a,
    label {
      color: #fff;
      position: relative;
      padding: 2px 4px;
      background: #5499c7;
    }
    
    .dropdown a {
      font-size: 1.6rem;
      margin-left: 1.4rem;
      border-radius: 50%;
    }
    
    .dropdown label {
      font-size: 1.6rem;
      text-align: left;
      margin: 0rem;
      cursor: pointer;
    }
    
    .dropdown>*:first-child {
      flex-grow: 1;
    }
    <link rel="stylesheet" href="https://maxst.icons8.com/vue-static/landings/line-awesome/line-awesome/1.3.0/css/line-awesome.min.css">
    <header>
      <div class="header-content">
        <div class="dropdown">
          <span>
            <label for="menu-toggle"><span class="las la-bars"></span></label>
          </span>
          <a href="#">
            <span class="las la-home"></span>
          </a>
          <a href="#">
            <span class="las la-envelope"></span>
          </a>
          <a href="#">
            <span class="las la-bell"></span>
          </a>
          <a href="#">
            <span class="las la-user"></span>
          </a>
        </div>
      </div>
    </header>
    Login or Signup to reply.
  3. I would suggest wrapping the a tags in a nav element, and using justify-content: space-between on .dropdown rather than justify-content: right

    header {
      position: fixed;
      right: 0;
      top: 0;
      left: 0;
      z-index: 100;
      height: 60px;
      box-shadow: 0px 5px 5px -5px rgb(0 0 0 /10%);
      background-color: #2980b9;
      transition: left 300ms;
    }
    
    .header-content {
      display: flex;
      align-items: center;
      height: 100%;
    }
    
    .dropdown {
      display: flex;
      position: relative;
      align-items: center;
      justify-content: space-between;
      padding: 4px;
      margin: 0px 15px;
      width: 100%;
      border: 1px solid #5499c7;
    }
    
    .dropdown a,
    label {
      color: #fff;
      position: relative;
      Padding: 2px 4px;
      background: #5499c7;
    }
    
    .dropdown a {
      font-size: 1.6rem;
      margin-left: 1.4rem;
      border-radius: 50%;
    }
    
    .dropdown label {
      font-size: 1.6rem;
      text-align: left;
      margin: 0rem;
      cursor: pointer;
      float: left;
    }
    
    .dropdown nav{
       display: flex;
       align-items: center;
    }
    <link rel="stylesheet" href="https://maxst.icons8.com/vue-static/landings/line-awesome/line-awesome/1.3.0/css/line-awesome.min.css">
    <header>
      <div class="header-content">
        <div class="dropdown">
          <label for="menu-toggle">
            <span class="las la-bars"></span>
          </label>
    
          <nav>
            <a href="#">
              <span class="las la-home"></span>
            </a>
    
            <a href="#">
              <span class="las la-envelope"></span>
            </a>
    
            <a href="#">
              <span class="las la-bell"></span>
            </a>
    
            <a href="#">
              <span class="las la-user"></span>
            </a>
          </nav>
    
        </div>
      </div>
    </header>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search