Search code examples
cssnavbarpadding

Change navbar logo padding


I was trying to style logo with padding and yellow background (similar to vox.com website).

The vox website has navbar logo with yellow background and padding:

padding-top: 8px;
padding-right: 16px;
padding-bottom: 8px;
padding-left: 16px;

This make it create a cool effect with the logo appearing to protrude to body section.

I was trying to create the same effect on the site raachotrekkers.com, but it did not happen.

The Vox site is using an SVG logo, whereas I'm using a PNG image.

Is this the reason?


Solution

  • You can achieve this by using position:absolute; and then top:0;

    here is the code

    *{
      margin:0;
      padding:0;
      box-sizing: border-box;
    }
    nav{
      padding:0 10%;
      display:flex;
      align-items:center;
      min-height:50px;
      max-height:80px;
      box-shadow:0 2px 10px 0 rgb(0 0 0 / 16%);
    }
    .brand{
      position:absolute;
      top:0;
    }
    .navlogo{
      width:180px;
    }
    .rightele{
      display:flex;
      justify-content:right;
      width:100%;
    }
    
    .rightele>*{
      align-items:center;
      display:flex;
      justify-content:center;
    }
    .rightele ul li{
    /*   padding:5px 10px; */
       list-style-type: none;
    }
    .rightele ul li,
    .rightele button{
        margin:5px 10px;
        cursor:pointer;
    }
    .rightele button{
      height:40px;
      padding:5px 10px;
      color:white;
      font-weight:800;
      background-color:#161616;
    }
    <nav>
      <div class="brand">
        <img class="navlogo" src="https://mlmgm6ui7ujb.i.optimole.com/Z_NXo3Y.9AP_~52a37/w:auto/h:auto/q:85/https://raachotrekkers.com/wp-content/uploads/2020/05/Raacho-Trekkers-Logo.gif">
      </div> 
      <div class="rightele">
        <ul>
          <li>Home</li>
          <li>About Us</li>
          <li>Blog</li>
          <li>Road Trip</li>
        </ul>
        <button>TALK TO US</button>
      </div>
    </nav>

    I did not add CSS for the mobile view because you probably want a burger icon over there and hide all options.

    So open this in full screen