css 尽管显示灵活,但菜单和文本未对齐

ddarikpa  于 2023-03-24  发布在  其他
关注(0)|答案(1)|浏览(91)

我正在尝试复制这个网站来练习:https://www.arte.tv/fr/videos/documentaires-et-reportages/
我尝试创建导航栏,我不知道为什么左边的线不会在同一条线上对齐,他们骑在对方而不是在同一条线上。导航栏的左边部分在同一条线上对齐,但右边部分不知道为什么。
老实说,我开始觉得自己是个笨蛋,一个月以来我每天都在CSS上花4个小时,但我仍然不能做一个该死的导航栏。
下面是我的HTML和CSS:

* {
  list-style: none;
  background-color: black;
  font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande",
    "Lucida Sans Unicode", Geneva, Verdana, sans-serif;
  color: rgb(221, 213, 213);
  margin: 0;
  padding: 0;
}

.arte-logo {
  height: 45px;
  margin: 0;
}

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-left ul {
  display: flex;
}

.nav-right ul {
  display: flex;
}
<!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>Ducumentaires et reportages</title>
    <link rel="stylesheet" href="style.css" />
    <link
      rel="icon"
      href="/Users/jeandizian/Documents/Code/space/Arte/Assets/imgs/arte-icon.png"
    />
  </head>
  <body>
    <nav>
      <div class="nav-left">
        <ul>
          <li>
            <img
              class="arte-logo"
              src="/Users/jeandizian/Documents/Code/space/Arte/Assets/imgs/arte-logo.png"
              alt="arte logo"
              ;
            />
          </li>
          <li><span>&#9783;</span></li>
          <li>Guide TV</li>
          <li>Direct</li>
          <li>Bientôt en ligne</li>
          <li>Arte Concert</li>
        </ul>
      </div>
      <div class="nav-right">
        <ul>
          <li><span>&#9784;</span></li>
          <li><span>&#8853;</span></li>
          <div class="connecter">
            <li><span>&#9865;</span></li>
            <li>Se connecter</li>
          </div>
          <li>ARTE en 6 langues</li>
        </ul>
      </div>
    </nav>
  </body>
</html>
eyh26e7m

eyh26e7m1#

在导航栏上有align-items: center是不够的。这只是对齐nav-leftnav-right元素。您还需要确保这些元素内部的元素对齐。

* {
  list-style: none;
  background-color: black;
  font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande",
    "Lucida Sans Unicode", Geneva, Verdana, sans-serif;
  color: rgb(221, 213, 213);
  margin: 0;
  padding: 0;
}

.arte-logo {
  height: 45px;
  margin: 0;
}

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-left ul {
  display: flex;
  align-items: center;
}

.nav-right ul {
  display: flex;
  align-items: center;
}

.connecter {
  display: flex;
  align-items: center;
}
<!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>Ducumentaires et reportages</title>
    <link rel="stylesheet" href="style.css" />
    <link
      rel="icon"
      href="/Users/jeandizian/Documents/Code/space/Arte/Assets/imgs/arte-icon.png"
    />
  </head>
  <body>
    <nav>
      <div class="nav-left">
        <ul>
          <li>
            <img
              class="arte-logo"
              src="/Users/jeandizian/Documents/Code/space/Arte/Assets/imgs/arte-logo.png"
              alt="arte logo"
              ;
            />
          </li>
          <li><span>&#9783;</span></li>
          <li>Guide TV</li>
          <li>Direct</li>
          <li>Bientôt en ligne</li>
          <li>Arte Concert</li>
        </ul>
      </div>
      <div class="nav-right">
        <ul>
          <li><span>&#9784;</span></li>
          <li><span>&#8853;</span></li>
          <div class="connecter">
            <li><span>&#9865;</span></li>
            <li>Se connecter</li>
          </div>
          <li>ARTE en 6 langues</li>
        </ul>
      </div>
    </nav>
  </body>
</html>

相关问题