锚标记不会跳

时间:2019-05-15 10:27:43

标签: javascript html css

我不明白我的代码有什么问题。这可能是我看不到的可笑的小东西。

基本上,我在导航栏中的定位标记无法正常工作。我将它们设置为页面下部的ID的id,但是当我单击“链接”时,它们不会像我期望的那样跳跃。最终,我想创建一个平滑的滚动,并且我知道该在哪里找到资源,但这不是问题,因为链接没有响应。

我使用了带有工作导航栏和平滑滚动功能的工作模板。然后,我尝试用图像替换最初是h1标签和段落的内容。当我完成替换后,跳跃和平滑滚动功能都坏了:(

当我单击导航栏时,只有一点动静,图像加载正常。

* {
  margin: 0;
  padding: 0;
}

body {
  font-family: Century Gothic,CenturyGothic,AppleGothic,sans-serif; 
  background: #fff;
  color: #000;
  height: 100vh;
  line-height: 1.6;
  overflow: hidden;
}

.container {
  width: 100%;
  height: 100%;
  /* CSS Smooth Scroll */
  overflow-y: scroll; 
  scroll-behavior: smooth;
  scroll-snap-type: y mandatory;
}

.lead {
  font-size: 1.5rem;
}

.navbar {
  position: fixed;
  top: 0;
  z-index: 1;
  display: flex;
  width: 100%;
  height: 60px;
  background: white;
}

.navbar ul {
  display: flex;
  list-style: none;
  width: 100%;
  justify-content: center;
}

.navbar ul li {
  margin: 0 1rem;
  padding: 1rem;
}

.navbar ul li a {
  text-decoration: none;
  text-transform: uppercase;
  color: #000;
}

.navbar ul li a:hover {
  color: skyblue;
}

section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  height: 100vh;

  /* Scroll Snap */
  scroll-snap-align: center;
}
<div class="container">
    <nav class="navbar">
        <ul>
            <li><a href="index.html"><img src = "pics/logo.png" alt = "logo" class = "logo"></a></li>
            <li><a href="#how">How it Works</a></li>
            <li><a href="#why">Why Learning Time?</a></li>
            <li><a href="#program">Programs</a></li>
            <li><a href="#about">About Us</a></li>                    
            <li><a href="#community">Our Community</a></li>
            <li><a href="#gift">Gift Card</a></li>
        </ul>
    </nav>
    <section id="start">
        <h1>Start</h1>
        <img class = "block-image" src = "pics\1.png"></a>
    </section>
    <section id="how">
        <h1>Start</h1>
        <img class = "block-image" src = "pics\how-it-works.png">
    </section>
    <section id="why">
        <h1>Start</h1>
        <img class = "block-image" src = "pics\why-learning-time.png">
    </section>
    <section id="program">
        <h1>Start</h1>
        <a href = "program.html"><img class = "block-image-program" src = "pics\Programs.png"></a>
    </section>
    <section id="about">
        <h1>Start</h1>
        <img class = "block-image" src = "pics\About-Us.png">
    </section>
    <section id="community">
        <h1>Start</h1>
        <img src = "pics\LT-Community.png">
    </section>
</div>

0 个答案:

没有答案