Justify-Content: Space Between 工作不正常

Justify-Content: Space Between isn't working properly

我 运行 我的代码存在一些问题。我的 header 中有一个导航栏,我想在两者之间添加一些 space。我希望我的链接位于 header 的一侧,而我的公司名称位于另一侧。但是,当我执行 space-between 时,它会将我的链接放在页面的中心。我以前在我的 header 中也有一个材料图标,但我将显示设置为 none(直到它满足我的媒体查询的条件),我认为这可以解决问题,但事实并非如此。对解决这个问题有什么建议吗?

/* Site-wide */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  display: flex;
  flex-direction: column;
  /* height: 100%; */
}


/* Header */

header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  background-color: lightgray;
  align-items: center;
  padding: 0px 0px 5px 5px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}

.logo {
  font-size: 2vh;
}

header a {
  text-decoration: none;
  color: white;
  padding-right: 10px;
}

.material-icons {
  display: none;
}


/* Main */

main {
  display: flex;
  padding-left: 5px;
  margin-top: 50px;
  flex-wrap: wrap;
  /* justify-content: space-around; */
}

.card {
  border: 1px solid black;
  height: 350px;
  width: 300px;
  /* margin: 5rem; */
  margin: 0 20px 2rem 5px;
  background-color: rgba(211, 211, 211, 0.251);
}

.card h3 {
  background-color: rgba(185, 44, 185, 0.803);
  padding-left: 3px;
}

.card p {
  padding-left: 5px;
}


/* Footer */

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: lightgray;
  text-align: center;
}


/* Media Queries */

@media(max-width:768px) {
  .hamburger {
    display: none;
  }
  .material-icons {
    display: block;
  }
  main {
    display: flex;
    flex-wrap: wrap;
  }
  .card {
    flex-basis: auto;
  }
  .card h3,
  p {
    font-size: 20px;
  }
}
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
  <link rel="stylesheet" href="media.css">
</head>

<body>
  <header>
    <span class="logo">Company Name</span>
    <nav>
      <a href="">Link One</a>
      <a href="">Link Two</a>
      <a href="">Link Three</a>
    </nav>
    <a class="hamburger"><i class="material-icons">menu</i></a>
  </header>
  <main>
    <div class="card">
      <h3>Card Title</h3>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptates, dolor eveniet consequatur aliquid id quo quam architecto accusantium ipsam et officia temporibus nesciunt hic officiis totam fugiat doloremque iusto amet.</p>
    </div>
    <div class="card">
      <h3>Card Title</h3>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptates, dolor eveniet consequatur aliquid id quo quam architecto accusantium ipsam et officia temporibus nesciunt hic officiis totam fugiat doloremque iusto amet.</p>
    </div>
    <div class="card">
      <h3>Card Title</h3>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptates, dolor eveniet consequatur aliquid id quo quam architecto accusantium ipsam et officia temporibus nesciunt hic officiis totam fugiat doloremque iusto amet.</p>
    </div>
    <div class="card">
      <h3>Card Title</h3>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptates, dolor eveniet consequatur aliquid id quo quam architecto accusantium ipsam et officia temporibus nesciunt hic officiis totam fugiat doloremque iusto amet.</p>
    </div>
    <div class="card">
      <h3>Card Title</h3>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptates, dolor eveniet consequatur aliquid id quo quam architecto accusantium ipsam et officia temporibus nesciunt hic officiis totam fugiat doloremque iusto amet.</p>
    </div>
    <div class="card">
      <h3>Card Title</h3>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptates, dolor eveniet consequatur aliquid id quo quam architecto accusantium ipsam et officia temporibus nesciunt hic officiis totam fugiat doloremque iusto amet.</p>
    </div>
  </main>
  <footer>
    Copyright 2009
  </footer>
</body>

</html>

nav 上指定 margin-left: auto;

/* Site-wide */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  display: flex;
  flex-direction: column;
  /* height: 100%; */
}


/* Header */

header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  background-color: lightgray;
  align-items: center;
  padding: 0px 0px 5px 5px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}

.logo {
  font-size: 2vh;
}

header a {
  text-decoration: none;
  color: white;
  padding-right: 10px;
}

.material-icons {
  display: none;
}


/* Main */

main {
  display: flex;
  padding-left: 5px;
  margin-top: 50px;
  flex-wrap: wrap;
  /* justify-content: space-around; */
}

.card {
  border: 1px solid black;
  height: 350px;
  width: 300px;
  /* margin: 5rem; */
  margin: 0 20px 2rem 5px;
  background-color: rgba(211, 211, 211, 0.251);
}

.card h3 {
  background-color: rgba(185, 44, 185, 0.803);
  padding-left: 3px;
}

.card p {
  padding-left: 5px;
}


/* Footer */

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: lightgray;
  text-align: center;
}


/* Media Queries */

@media(max-width:768px) {
  .hamburger {
    display: none;
  }
  .material-icons {
    display: block;
  }
  main {
    display: flex;
    flex-wrap: wrap;
  }
  .card {
    flex-basis: auto;
  }
  .card h3,
  p {
    font-size: 20px;
  }
}

nav {
  margin-left: auto;
}
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
  <link rel="stylesheet" href="media.css">
</head>

<body>
  <header>
    <span class="logo">Company Name</span>
    <nav>
      <a href="">Link One</a>
      <a href="">Link Two</a>
      <a href="">Link Three</a>
    </nav>
    <a class="hamburger"><i class="material-icons">menu</i></a>
  </header>
  <main>
    <div class="card">
      <h3>Card Title</h3>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptates, dolor eveniet consequatur aliquid id quo quam architecto accusantium ipsam et officia temporibus nesciunt hic officiis totam fugiat doloremque iusto amet.</p>
    </div>
    <div class="card">
      <h3>Card Title</h3>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptates, dolor eveniet consequatur aliquid id quo quam architecto accusantium ipsam et officia temporibus nesciunt hic officiis totam fugiat doloremque iusto amet.</p>
    </div>
    <div class="card">
      <h3>Card Title</h3>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptates, dolor eveniet consequatur aliquid id quo quam architecto accusantium ipsam et officia temporibus nesciunt hic officiis totam fugiat doloremque iusto amet.</p>
    </div>
    <div class="card">
      <h3>Card Title</h3>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptates, dolor eveniet consequatur aliquid id quo quam architecto accusantium ipsam et officia temporibus nesciunt hic officiis totam fugiat doloremque iusto amet.</p>
    </div>
    <div class="card">
      <h3>Card Title</h3>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptates, dolor eveniet consequatur aliquid id quo quam architecto accusantium ipsam et officia temporibus nesciunt hic officiis totam fugiat doloremque iusto amet.</p>
    </div>
    <div class="card">
      <h3>Card Title</h3>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptates, dolor eveniet consequatur aliquid id quo quam architecto accusantium ipsam et officia temporibus nesciunt hic officiis totam fugiat doloremque iusto amet.</p>
    </div>
  </main>
  <footer>
    Copyright 2009
  </footer>
</body>

</html>