0

I want to create responsive navigation bar in flexbox. The problem is facing is to align the bar in center of container. I tried justify-content:center and text-align:center while using these i found some empty space left before nav bar is not aligning center perfectly in mobile screens please review my code and help me!

Html document

<!DOCTYPE html>
<html lang="en">

<head>
    <link href="https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:200,300,400,700" rel="stylesheet"
        type="text/css">
    <link rel="stylesheet" href="style.css" />
    <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>Document</title>
</head>

<body>
    <div class="box">
        <div>
            <nav>
                <ul>
                    <li>Home</li>
                    <li>Service</li>
                    <li>About</li>
                </ul>
            </nav>
        </div>
    </div>
</body>

</html>

Css styling

.box  ul{
  list-style: none;
  border: 1px solid;
  display: flex;
  justify-content: space-between;
}
.box li{
  border: 1px solid;
}

Screenshot of responsive navbar image in mobile view:

Screen shot of responsive nav bar image in mobile view

Screenshot of responsive navbar image in Desktop view:

Screen shot of responsive nav bar image in Desktop view

AnsonH
  • 2,460
  • 2
  • 15
  • 29
Abhiram010
  • 3
  • 1
  • 3
  • I dont understand what you are trying to achieve. Can you please describe what do you want to do with navbar. – JithinAji May 13 '21 at 05:14

1 Answers1

0

Space that comes before Home is because of padding in ul. You need to remove the padding from ul.

.box ul {
  list-style: none;
  border: 1px solid;
  display: flex;
  justify-content: space-between;
}

ul {
  padding: 0;
}

.box li {
  border: 1px solid;
}
<div class="box">
  <div>
    <nav>
      <ul>
        <li>Home</li>
        <li>Service</li>
        <li>About</li>
      </ul>
    </nav>
  </div>
</div>
DecPK
  • 24,537
  • 6
  • 26
  • 42