Почему мой фиксированный navbar не работает с изображениями? - PullRequest
1 голос
/ 06 апреля 2020

Я хотел попробовать фиксированную панель навигации, но изображения перекрывают панель навигации. если вы прокрутите мою страницу, изображения go поверх панели навигации и других элементов ниже. Есть ли способ это исправить? Я подозреваю, что это касается относительного положения моей фигуры, но я не знаю, как это изменить.
Также приветствуются все предложения. Я новичок ie, и я хочу учиться. Заранее спасибо. Мой HTML:


<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Cats</title>
        <meta name="description" content="Cats and other cute things">
        <meta name="author" content="Daniel Parpart">
        <link type="text/css" rel="stylesheet" media="screen" href="stylesheet.css" />
    </head>
    <body>
      <div class="grid">
        <header class="header">
         <nav>
          <ul>
            <li><a href="#">Start</a></li>
            <li><a href="#">Gallery</a></li>
            <li><a href="#">About me</a></li>
          </ul>
        </nav>
       </header>
        <div class="main">
          <figure id="p">
            <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/7b/Gr%C3%BCne_Augen_einer_Katze.JPG/800px-Gr%C3%BCne_Augen_einer_Katze.JPG" alt="cat">
            <figcaption>Picture by 4028mdk09 / <a href="https://creativecommons.org/licenses/by-sa/3.0">CC BY-SA</a></figcaption>
          </figure>
          <h2>Why are cats so cute?</h2>
          <p>
            Est constias sed mentitum eu fabulas illum ipsum commodo aute.

            Do sunt quamquam comprehenderit, ullamco fugiat est probant exquisitaque.

            Singulis ut quorum litteris e hic an quorum cillum aliqua.

            Incididunt eruditionem aut appellat ad laborum est veniam eiusmod.

            Mandaremus esse cernantur probant, fabulas o cupidatat.

            Culpa ea incididunt ad culpa concursionibus incurreret quid voluptate.

            Officia legam deserunt, veniam praesentibus commodo nulla constias.
          <h3>Five reasons to live</h3>
          </p>
          <figure id="p">
            <img src="https://upload.wikimedia.org/wikipedia/commons/0/0b/Cat_poster_1.jpg" alt="different types of cats">
            <figcaption>Alvesgaspar / <a href="https://creativecommons.org/licenses/by-sa/3.0">CC BY-SA</a></figcaption>
          </figure>
          <p>
            Quo dolore singulis ingeniis aut quo ea illustriora.
          </p>
          <h3>Another one bits the dust</h3>
          <p>
            Fugiat aliquip excepteur in quibusdam multos illum cernantur dolor.
          </p>
        </div>
        <div class="sidebar">
          <h4>Advertisment</h4>
          <figure id="ad">
            <img src="https://upload.wikimedia.org/wikipedia/commons/2/2b/Bundesarchiv_Bild_183-R94483%2C_Leipzig%2C_Reklame_f%C3%BCr_Fahrradbereifung.jpg" alt="ad">
            <figcaption>Bundesarchiv, Bild 183-R94483 / <a href="https://creativecommons.org/licenses/by-sa/3.0/de/deed.en">CC-BY-SA 3.0 / CC BY-SA 3.0 DE</a> </figcaption>
          </figure>
          <p>
          Elit graviterque nescius quae deserunt, pariatur nulla incididunt incurreret.

          Incididunt in illum, ut fugiat philosophari.</p>
        </div>
        <div class="twitter">
          <a class="twitter-timeline" data-height="1400" href="https://twitter.com/Ophur_Cat?ref_src=twsrc%5Etfw">Tweets by Ophur_Cat</a> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
        </div>
        <footer class="footer">
          <p>This is a test website.</p>
        </footer>
      </div>
    </body>

</html>

Мой CSS:

  background-color: white;
  margin-top: 40px;
}
header {
  background-color: #173753;
  width: auto;
  border-radius: 25px;
}
/*navbar*/
ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #173753;
  border-radius: 15px;
  position: fixed;
  overflow: hidden;
  top: 0;
  width: 100%;
}

li {
  float: left;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

/* Change the link color to #111 (black) on hover */
li a:hover {
  background-color: #111;
}
h4 {
  clear: both;
  position: relative;
  text-align: center;
}
p {
  margin: 25px;
  text-align: justify;
  /*text-indent: 2em;*/
}
footer {
  background-color: #173753;
  text-align: center;
  border-radius: 25px;
}

.header {
  grid-area: header;
  text-align: center;
}
.main {
  grid-area: main;
  background-color: #7fb7be;
  border-radius: 15px;
}
.sidebar {
  grid-area: sidebar;
  align-content: center;
  align-items: center;
}
.footer {
  grid-area: footer;
}
.twitter {
  grid-area: twitter;
}
.grid {
  display: grid;
  grid-template-columns: 3fr;
  grid-template-rows: auto;
  justify-content: center;
  align-content: center;
  grid-template-areas:
  "header"
  "main"
  "sidebar"
  "footer"
  }
  img {
    width: 100%;
    height: auto;
    border-radius: 25px;
  }
  @media screen and (max-width: 480px) {
    .twitter {display:none;}
    h2 {
      clear: both;
      position: relative;
      text-align: center;
    }
    h3 {
      clear: both;
      position: relative;
      text-align: center;
    }
  }
  @media only screen and (min-width: 768px) {
    .grid {
      display: grid;
      grid-template-columns: 1fr 3fr 1fr;
      grid-template-rows: auto;
      justify-content: center;
      align-content: center;
      grid-gap: 5px;
      grid-template-areas:
      "header header header"
      "sidebar main twitter"
      "footer footer footer"
    }

}
figcaption {
  background-color: black;
  color: white;
  max-width: 400px;
  font-size: 10px;
  display: block;
  float: left;
  position: absolute;
  top: 0;
  margin: 15px 15px auto 15px;

}


figure {
  position: relative;
  float: left;
}
a {
  color: white;
  text-decoration: none;
}

1 Ответ

1 голос
/ 06 апреля 2020

Вероятно, это проблема z-index: https://developer.mozilla.org/en-US/docs/Web/CSS/z-index

Добавьте z-index:n и position:fixed к элементу заголовка. Значением z-индекса может быть любое число, если оно больше 0 и выше, чем z-index для других элементов на странице.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...