我如何 space 在导航栏中平均分配链接?

How do I space out the links equally in a nav bar?

大家好,我是 html 和 css 的新手,我无法 space 导航栏中的链接。

这就是我想要得到的:image

这是我目前拥有的:

.topnav {
  overflow: hidden;
  background-color: white;
  border: 5px solid black;
}

.topnav a {
  float: left;
  display: block;
  color: black;
  text-align: center;
  padding: 14px 30px;
  text-decoration: none;
  font-size: 17px;
  border-bottom: 3px solid transparent;
}
<h1>ABOUT ME</h1>
<div class="topnav">
  <nav>
    <ul>
      <a href="aboutme.html">About Me</a>
      <a href="mypast.html">My Past</a>
      <a href="mypresent.html">My Present</a>
      <a href="myfuture.html">My Future</a>
      <a href="feedback.html">Feedback</a>

    </ul>
  </nav>
</div>

.topnav {
 overflow: hidden;
 background-color: white;
border: 5px solid black;

}

.topnav a {
float: left;
display: block;
color: black;
text-align: center;
padding: 14px 30px;
text-decoration: none;
font-size: 17px;
border-bottom: 3px solid transparent;


}

ul {
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding : 0;
}
<h1>ABOUT ME</h1>
<div class="topnav">
<nav>
  <ul>
     <a href="aboutme.html">About Me</a>
     <a href="mypast.html">My Past</a>
     <a href="mypresent.html">My Present</a>
     <a href="myfuture.html">My Future</a>
     <a href="feedback.html">Feedback</a>
     
  </ul>
</nav>
</div>

我已将您的导航元素重命名为“topnav”class。使用 display flex 代替显示块,因为它有助于重新调整您的项目以相对于导航栏做出响应。您可以使用 justify-contents: space-evenly 来确保每个文本项之间的距离相等。

我附上了下面的示例代码片段供您测试!

 .topnav {
     overflow: hidden;
     background-color: white;
     border: 5px solid black;

 }

 .topnav ul {
     display: flex;
     justify-content: space-evenly;
     color: black;
     text-align: center;
     text-decoration: none;
     font-size: 17px;
     border-bottom: 3px solid transparent;
 }

 .topnav ul a {
     text-decoration: none;
 }
<body>
<h1>ABOUT ME</h1>
<nav class="topnav">
  <ul>
     <a href="aboutme.html">About Me</a>
     <a href="mypast.html">My Past</a>
     <a href="mypresent.html">My Present</a>
     <a href="myfuture.html">My Future</a>
     <a href="feedback.html">Feedback</a>
  </ul>
</nav>

</body>

.topnav ul {
  display: flex;
  justify-content: space-around;
}
.topnav a {
    display: inline-block;
    color: black;
    background-color: rgb(233, 233, 233);
    text-align: center;
    padding: 5px;
    text-decoration: none;
    font-size: 17px;
    flex: 1;
    border: 3px solid black;
}

ul{
    display: flex;
    justify-content: center;
    border-left: 2px solid black;
    border-right: 2px solid black;
    border-top: 5px solid black;
    border-bottom: 5px solid black;
    padding: 0;
    background-color: black;
}