HTML навигационные ссылки не активируются - PullRequest
0 голосов
/ 29 января 2019

На прошлой неделе я изучал HTML и CSS и решил возиться с панелью навигации.У меня все настроено, но теперь ссылки вверху не кликабельны?Я проверил, чтобы убедиться, что я не пропустил ничего простого, например закрывающий тег, но не смог найти ничего подобного.

* {
  margin: 0;
  padding: 0;
}

html {
  background-color: #808080;
  background-image: url("https://hdqwalls.com/download/simple-gray-abstract-background-wi-1920x1080.jpg");
  background-repeat: no-repeat;
}

#landing__container {
  height: 100vh;
  width: 100%;
}

header {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(255, 0, 0, 0.4);
}

header h1 {
  color: white;
  font-family: impact;
  font-weight: normal;
}

header ul {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: 30px;
}

header ul li {
  list-style: none;
}

header a {
  font-family: helvetica;
  font-weight: bold;
  font-size: 18px;
  text-decoration: none;
  color: white;
  margin: 30px;
}

#landing__center {
  display: flex;
  flex-direction: column;
  text-align: center;
  justify-content: center;
  align-items: center;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  position: absolute;
}

#landing__center h2 {
  padding-bottom: 20px;
  color: white;
  font-family: Impact;
  font-weight: normal;
  font-size: 40px;
}

#landing__center p {
  padding-top: 20px;
  color: white;
  font-family: helvetica;
  font-weight: normal;
  font-size: 20px;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Navigation Bar Practice</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
  </head>

  <body>
    <div id="landing__container">
      <!-- Navigation Bar -->
      <header>
        <nav id="nav__bar">
          <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Documentation</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </nav>
      </header>

      <section id="landing__center">
        <h2>Testing</h2>
        <p>
          Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rem
          voluptatum asperiores illum maiores aliquid quo perferendis,
          blanditiis facere temporibus laudantium!
        </p>
      </section>
    </div>
  </body>
</html>

Я знаю, что код может быть не идеальным и / или чистым, но имейте в виду, что я делал это в течение недели.

Ответы [ 3 ]

0 голосов
/ 29 января 2019

Вам необходимо добавить z-index вместе с position: relative в ваш код

header{
  z-index: 1;
  position: relative;
}
0 голосов
/ 29 января 2019

Проблема вызвана тем, что #landing__center закрывает панель навигации, потому что в качестве элемента, относящегося к

, выбран #landing__container. Один из способов - создать оболочку, которая будет действовать как контейнер#landing__center вместо #landing__container.Так что это относительно его собственного контейнера, а не его родителя, не мешая его братьям и сестрам

* {
  margin: 0;
  padding: 0;
}

html {
  background-color: #808080;
  background-image: url("https://hdqwalls.com/download/simple-gray-abstract-background-wi-1920x1080.jpg");
  background-repeat: no-repeat;
}

#landing__container {
  height: 100vh;
  width: 100%;
}

header {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(255, 0, 0, 0.4);
}

header h1 {
  color: white;
  font-family: impact;
  font-weight: normal;
}

header ul {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: 30px;
}

header ul li {
  list-style: none;
}

header a {
  font-family: helvetica;
  font-weight: bold;
  font-size: 18px;
  text-decoration: none;
  color: white;
  margin: 30px;
}

.wrapper {
  position: relative;
  height: 95%;
}

#landing__center {
  display: flex;
  flex-direction: column;
  text-align: center;
  justify-content: center;
  align-items: center;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  position: absolute;
}

#landing__center h2 {
  padding-bottom: 20px;
  color: white;
  font-family: Impact;
  font-weight: normal;
  font-size: 40px;
}

#landing__center p {
  padding-top: 20px;
  color: white;
  font-family: helvetica;
  font-weight: normal;
  font-size: 20px;
}
<body>
  <div id="landing__container">
    <!-- Navigation Bar -->
    <header>
      <nav id="nav__bar">
        <ul>
          <li><a href="#">Home</a></li>
          <li><a href="#">Documentation</a></li>
          <li><a href="#">About</a></li>
          <li><a href="#">Contact</a></li>
        </ul>
      </nav>
    </header>

    <div class="wrapper">
      <section id="landing__center">
        <h2>Testing</h2>
        <p>
          Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rem voluptatum asperiores illum maiores aliquid quo perferendis, blanditiis facere temporibus laudantium!
        </p>
      </section>
    </div>
  </div>
</body>
0 голосов
/ 29 января 2019

Вы сделали этот раздел #landing__center position:absolute и top:0, поэтому он шел поверх navbar.Я увеличил вершину до 30. Спасибо

* {
  margin: 0;
  padding: 0;
}

html {
  background-color: #808080;
  background-image: url("https://hdqwalls.com/download/simple-gray-abstract-background-wi-1920x1080.jpg");
  background-repeat: no-repeat;
}

#landing__container {
  height: 100vh;
  width: 100%;
}

header {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(255, 0, 0, 0.4);
}

header h1 {
  color: white;
  font-family: impact;
  font-weight: normal;
}

header ul {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: 30px;
}

header ul li {
  list-style: none;
}

header a {
  font-family: helvetica;
  font-weight: bold;
  font-size: 18px;
  text-decoration: none;
  color: white;
  margin: 30px;
}

#landing__center {
  display: flex;
  flex-direction: column;
  text-align: center;
  justify-content: center;
  align-items: center;
  top: 30; /*changed*/
  bottom: 0;
  left: 0;
  right: 0;
  position: absolute;
}

#landing__center h2 {
  padding-bottom: 20px;
  color: white;
  font-family: Impact;
  font-weight: normal;
  font-size: 40px;
}

#landing__center p {
  padding-top: 20px;
  color: white;
  font-family: helvetica;
  font-weight: normal;
  font-size: 20px;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Navigation Bar Practice</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
  </head>

  <body>
    <div id="landing__container">
      <!-- Navigation Bar -->
      <header>
        <nav id="nav__bar">
          <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Documentation</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </nav>
      </header>

      <section id="landing__center">
        <h2>Testing</h2>
        <p>
          Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rem
          voluptatum asperiores illum maiores aliquid quo perferendis,
          blanditiis facere temporibus laudantium!
        </p>
      </section>
    </div>
  </body>
</html>
...