Home>

I want to justify the navigation bar logo to the left.

In the logo partmargin-right: autoIt doesn't change

Corresponding source code
<! DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8">
<meta name = "viewport" content = "width = device-width, initial-scale = 1.0">
<link rel = "stylesheet" href = "css/style.css">
<link rel = "stylesheet" href = "css/reset.css">
<title>Title</title>
</head>
<body>
<header>
  <nav>
    <ul>
      <li>logo</li>
      <li>nav-item</li>
      <li>nav-item</li>
      <li>nav-item</li>
      <li>nav-item</li>
      <li>nav-item</li>
      <li>nav-item</li>
    </ul>
  </nav>
</header>
</body>
</html>
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
.header {
  width: 100%;
  height: 10vh;
}
.nav {
  width: 70%;
  height: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
}
.nav-list {
  display: flex;
}
.logo {
  margin-right: auto;
}
.nav-item {
  padding: 0 20px;
}
  • Answer # 1

    What if you specify the width of the parent element?

    .nav-list {
      display: flex;
      width: 100%;/* Add * /
    }

  • Answer # 2

    As hatena19 pointed out, it seems to be a problem of the width of the parent element.

    .nav-list {
      display: flex;
      flex-grow: 1;/* Flex extension factor of flex item * /
    }

Related articles