Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to put the logo text to the left corner using flexbox in this case?

Here I am trying to keep the navigation buttons in the center of the navbar using flexbox. But whenever I try to center using the justify-content property using flexbox the logo text also moves along the navigation buttons. I want the logo text on the left corner and buttons on the center. Any fix for this using flexbox?

/* -----------
   1. global-setup
   ----------- */

* {
    margin: 0;
    padding: 0;
}

/*  -----------
   2. navigation-container
   ----------- */

.nav {
    background-color: #BA8C63;
    width: 100%;
    height: 60px;
    display: flex;
    justify-content: center;
}

.nav .logo {
    display: flex;
    align-self: flex-start;
}

.nav .logo p {
    font-size: 30px;
    color: white;
    padding: 10px;
    font-family: 'Oleo Script', cursive;
    padding-left: 40px;

}

div.li ul {
    display: flex;
    list-style: none;
}

a {
    text-decoration: none;
    display: inline-block;
    color: #e6cbb3;
    font-size: 15px;
    text-transform: uppercase;
    padding: 20px;
}

a:hover {
    background-color: #e6cbb3;
    color: #BA8C63;
    transition: .5s;
}
<!DOCTYPE html>
<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>Flexbox Practice</title>
  <link rel="stylesheet" href="flexbox.css">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Oleo+Script&display=swap" rel="stylesheet">
</head>

<body>
  <div class="nav">
    <div class="logo">
      <p>Woody</p>
    </div>
    <div class="li">
      <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Portfolio</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </div>
  </div>
</body>

</html>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

/* -----------
   1. global-setup
   ----------- */

   * {
    margin: 0;
    padding: 0;
}

/*  -----------
   2. navigation-container
   ----------- */

.nav {
    background-color: #BA8C63;
    width: 100%;
    height: 60px;
    display: flex;

}

.nav .logo {
    display: flex;
    align-self: flex-start;
}
.li{
  display: flex;
  justify-content: center;/*same code but aplys for only li class not whole nav*/
  width: 100%;/*fill available space*/
}
.nav .logo p {
    font-size: 30px;
    color: white;
    padding: 10px;
    font-family: 'Oleo Script', cursive;
    padding-left: 40px;

}

div.li ul {
    display: flex;
    list-style: none;
}

a {
    text-decoration: none;
    display: inline-block;
    color: #e6cbb3;
    font-size: 15px;
    text-transform: uppercase;
    padding: 20px;
}

a:hover {
    background-color: #e6cbb3;
    color: #BA8C63;
    transition: .5s;
}
<!DOCTYPE html>
<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>Flexbox Practice</title>
  <link rel="stylesheet" href="flexbox.css">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Oleo+Script&display=swap" rel="stylesheet">
</head>

<body>
  <div class="nav">
    <div class="logo">
      <p>Woody</p>
    </div>
    <div class="li">
      <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Portfolio</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </div>
  </div>
</body>

</html>

here we apply center only for .li class (not for whole nav) and make the .li to fit the remaining space other than logo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading