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

Time:01-19

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 >
    <div >
      <p>Woody</p>
    </div>
    <div >
      <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>

CodePudding user response:

/* -----------
   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 >
    <div >
      <p>Woody</p>
    </div>
    <div >
      <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

CodePudding user response:

/* -----------
   1. global-setup
   ----------- */
  
* {
  margin: 0;
  padding: 0;
}
  
/*  -----------
   2. navigation-container
   ----------- */
  
.nav {
  background-color: #BA8C63;
  width: 100%;
  height: 60px;
  display: flex;
  justify-content: center;
}
  
.nav::after {
  content: "";
  flex: auto;
}
  
.nav .logo {
  flex: 1;
  display: flex;
  align-content: flex-start;
}
  
.nav .logo p {
  font-size: 30px;
  color: white;
  padding: 10px;
  font-family: 'Oleo Script', cursive;
  padding-left: 40px;
  
}
  
div.li ul {
  align-self: center;
  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 >
    <div >
      <p>Woody</p>
    </div>
    <div >
      <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>

  •  Tags:  
  • Related