为什么H1在移动版本中干扰Navbar?

发布于 2025-02-08 17:21:03 字数 3562 浏览 0 评论 0原文

我不知道为什么我的H1在移动版本中干扰Navbar。当我在移动版本中向下滚动Navbar时,H1会干扰Navbar,而我无法解决此问题。我该如何更改代码,以使其有效?

移动版中的图像在这里: https://i.sstatic.net/sj3vi.jpg

下面的代码:

.banner {
  background-image: url('../../../assets/images/natallia-nagorniak-tA3sJ4u09eU-unsplash.jpg');
  height: 800px;
  background-position: center center;
  background-size: 100%;
}

.content {
  top: 25%;
  left: 5%;
  position: absolute;
}

.content h1 {
  color: black;
  font-size: 3em;
  font-weight: bold;
}

.content a {
  text-decoration: none;
  background-color: var(--primary-color);
  color: #fff;
  padding: 15px 40px;
  border-radius: 5px;
}

.content a:hover {
  background-color: #64cff7;
  color: #fff;
}

.stepBox {
  background-color: #64cff7;
  padding: 20px 20px;
  border-radius: 5px;
  text-align: center;
}

.stepBox h1 {
  font-size: 30px;
  font-weight: bold;
  color: black;
}

.stepBox p {
  font-size: 20px;
  font-style: italic;
  color: #fff;
}

.highlight {
  color: var(--primary-color);
  font-weight: bold;
  font-style: italic;
  text-decoration: underline;
}

.cakebox {
  padding: 10px 5px;
}

.cakebox img {
  width: 100%;
  height: 250px;
  object-fit: cover;
  border-radius: 5px;
}

.cakebox h1 {
  font-size: 18px;
  margin-top: 20px;
  font-weight: bold;
}

.viewmorebtn {
  text-decoration: none;
  background-color: #64cff7;
  color: #fff;
  padding: 10px 10px;
  border-radius: 5px;
  font-size: 18px;
}

.viewmorebtn i {
  padding-left: 5px;
}

@media screen and (max-width:600px) {
  .banner {
    height: 600px;
  }
}
<div class="banner">
  <div class="content">
    <h1 class="mb-5">Čerstvé koláče <br/> priamo k tvojim dverám</h1>
    <a routerLink="menu">Objednaj teraz! <i class="bi bi-arrow-right"></i></a>
  </div>
</div>
<!-- step -->
<div class="container mt-5 mb-5">
  <h1 class="text-center">Ako získať <span class="highlight">čerstvé koláče</span></h1>
  <div class="row mt-3">
    <!-- one -->
    <div class="col-lg-4 mt-2">
      <div class="stepBox">
        <h1>1</h1>
        <p>vyberte koláč</p>
      </div>
    </div>
    <!-- two -->
    <div class="col-lg-4 mt-2">
      <div class="stepBox">
        <h1>2</h1>
        <p>vyplnte podrobnosti</p>
      </div>
    </div>
    <!-- three -->
    <div class="col-lg-4 mt-2">
      <div class="stepBox">
        <h1>3</h1>
        <p>doručenie vašej objednávky</p>
      </div>
    </div>
  </div>
</div>

<!-- cakebox -->
<div class="container mt-4 mb-4">
  <h1 class="text-center">Obľúbené produkty</h1>
  <div class="row">
    <div class="col-lg-3 mt-3" *ngFor="let ck of cakeData; index as i">
      <div class="cakebox" *ngIf="i<=3">
        <img src="{{ck.cakeImg}}" />
        <h1>{{ck.cakeName}}</h1>
        <p>{{ck.cakePrice | currency:'EUR'}}</p>
      </div>
    </div>
  </div>
  <a routerLink="menu" class="viewmorebtn">Zobraziť viac<i class="bi bi-arrow-right"></i></a>
</div>

谢谢您的回答!

I don't know why my H1 is interfering with navbar in mobile version. When I scroll down my navbar in mobile version, H1 interfering to the navbar and I can't fix this issue. How can I change my code, that it works ?

Image in mobile version is here: https://i.sstatic.net/SJ3vi.jpg

Code below:

.banner {
  background-image: url('../../../assets/images/natallia-nagorniak-tA3sJ4u09eU-unsplash.jpg');
  height: 800px;
  background-position: center center;
  background-size: 100%;
}

.content {
  top: 25%;
  left: 5%;
  position: absolute;
}

.content h1 {
  color: black;
  font-size: 3em;
  font-weight: bold;
}

.content a {
  text-decoration: none;
  background-color: var(--primary-color);
  color: #fff;
  padding: 15px 40px;
  border-radius: 5px;
}

.content a:hover {
  background-color: #64cff7;
  color: #fff;
}

.stepBox {
  background-color: #64cff7;
  padding: 20px 20px;
  border-radius: 5px;
  text-align: center;
}

.stepBox h1 {
  font-size: 30px;
  font-weight: bold;
  color: black;
}

.stepBox p {
  font-size: 20px;
  font-style: italic;
  color: #fff;
}

.highlight {
  color: var(--primary-color);
  font-weight: bold;
  font-style: italic;
  text-decoration: underline;
}

.cakebox {
  padding: 10px 5px;
}

.cakebox img {
  width: 100%;
  height: 250px;
  object-fit: cover;
  border-radius: 5px;
}

.cakebox h1 {
  font-size: 18px;
  margin-top: 20px;
  font-weight: bold;
}

.viewmorebtn {
  text-decoration: none;
  background-color: #64cff7;
  color: #fff;
  padding: 10px 10px;
  border-radius: 5px;
  font-size: 18px;
}

.viewmorebtn i {
  padding-left: 5px;
}

@media screen and (max-width:600px) {
  .banner {
    height: 600px;
  }
}
<div class="banner">
  <div class="content">
    <h1 class="mb-5">Čerstvé koláče <br/> priamo k tvojim dverám</h1>
    <a routerLink="menu">Objednaj teraz! <i class="bi bi-arrow-right"></i></a>
  </div>
</div>
<!-- step -->
<div class="container mt-5 mb-5">
  <h1 class="text-center">Ako získať <span class="highlight">čerstvé koláče</span></h1>
  <div class="row mt-3">
    <!-- one -->
    <div class="col-lg-4 mt-2">
      <div class="stepBox">
        <h1>1</h1>
        <p>vyberte koláč</p>
      </div>
    </div>
    <!-- two -->
    <div class="col-lg-4 mt-2">
      <div class="stepBox">
        <h1>2</h1>
        <p>vyplnte podrobnosti</p>
      </div>
    </div>
    <!-- three -->
    <div class="col-lg-4 mt-2">
      <div class="stepBox">
        <h1>3</h1>
        <p>doručenie vašej objednávky</p>
      </div>
    </div>
  </div>
</div>

<!-- cakebox -->
<div class="container mt-4 mb-4">
  <h1 class="text-center">Obľúbené produkty</h1>
  <div class="row">
    <div class="col-lg-3 mt-3" *ngFor="let ck of cakeData; index as i">
      <div class="cakebox" *ngIf="i<=3">
        <img src="{{ck.cakeImg}}" />
        <h1>{{ck.cakeName}}</h1>
        <p>{{ck.cakePrice | currency:'EUR'}}</p>
      </div>
    </div>
  </div>
  <a routerLink="menu" class="viewmorebtn">Zobraziť viac<i class="bi bi-arrow-right"></i></a>
</div>

Thank you for your answers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

王权女流氓 2025-02-15 17:21:03
.content {
  top: 25%;
  left: 5%;
  position: absolute;
}

H1的容器绝对位置。默认z index使其与具有较小z index值的其他元素重叠。

设置z-index .content divnavbar可能有助于解决问题。

.content {
  top: 25%;
  left: 5%;
  position: absolute;
  z-index: 10; /** something smaller than the z-index of the navbar **/
}

.navbar {
   ...
   z-index: 20; /** something bigger than the z-index of .content **/
}
.content {
  top: 25%;
  left: 5%;
  position: absolute;
}

The container of the h1 is positioned absolutely. The default z-index is causing it to overlap other elements which have a smaller z-index value.

Setting the z-index of the .content div and navbar may help to solve the problem.

.content {
  top: 25%;
  left: 5%;
  position: absolute;
  z-index: 10; /** something smaller than the z-index of the navbar **/
}

.navbar {
   ...
   z-index: 20; /** something bigger than the z-index of .content **/
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文