如何使用锚点将用户带到某个部分而不显示另一部分的一半?

时间:2017-03-23 13:14:53

标签: html css

当用户点击向下箭头按钮时,用户应该是第2部分。但是,第2部分页面并不完全适合它也会显示部分第3部分。

当用户点击箭头时,我该如何才能将用户带到每个尺寸比例且不显示其他部分的部分?

如果我加入min-height:100vh;,这就完成了工作。但是,如果我在第2部分的顶部添加文字,则无法看到。这是由于高度更高。因此,如何将顶部的文字放在顶部,以便正确放置在顶部,这样我就不必点击第1部分中的箭头进入第2部分,然后必须向上滚动一点才能看到文本。第2部分的顶部。

HTML / CSS

  <style>
    body {
      margin: 0;
      padding: 0;
    }

    .navbar.navbar-default {
      background-color: #4D5061;
      height: 10vh;
      z-index: 100;
    }

    .navbar.navbar-default ul {
      list-style-type: none;
      text-align: right;
    }

    .navbar.navbar-default ul li {
      display: inline-block;
    }

    .dropdown-menu li {
      text-align: center
    }

    .dropdown .dropdown-menu {
      background-color: #4D5061;
    }

    .dropdown .dropdown-menu a {
      color: white;
    }

    .navbar.navbar-default ul li a {
      display: inline-block;
      padding: 3.5vh 8px 4px;
      color: white;
      text-decoration: none;
      font-size: 14pt;
      font-family: 'Roboto', sans-serif;
    }

    .navbar.navbar-default ul li:after {
      content: '';
      position: absolute;
      right: 50%;
      bottom: 0;
      left: 50%;
      height: 3px;
      background-color: #FFFFFF;
      border-radius: 9px;
      transition: all .2s;
    }

    .navbar.navbar-default ul li a:hover {
      color: white;
    }

    .nav.navbar-nav,
    .nav.navbar-nav>li {
      float: none;
    }

    .navbar.navbar-default ul li:hover:after {
      right: 0;
      left: 0;
    }

    .nav-title {
      font-size: 14pt;
      margin: 0;
      top: 35px;
      left: 50px;
      width: 100%;
      position: absolute;
      text-align: center;
      color: white;
      font-family: 'Roboto', sans-serif;
    }

    .navbar.navbar-default ul.dropdown-menu li,
    .navbar.navbar-default ul.dropdown-menu li a {
      position: relative;
      display: block;
    }

    #logo {
      padding-top: 2vh;
      padding-left: 20px;
      float: left;
    }

    .hero {
      background: url("https://static.pexels.com/photos/48727/pexels-photo-48727.jpeg") center center no-repeat;;
      background-attachment: fixed;
      position: relative;
      background-size: cover;
      width: 100%;
      max-width: 100%;
      width: 100vw;
      height: 100%;
    }

    section {
      position: relative;
      height: 95vh;
    }

    .section1 {
      height: 100vh;
      text-align: center;
      color: white;
    }

    .section2 {
      background-color: #11B5E4;
      text-align: center;
      color: white;
    }

    .section3 {
      background-color: #FFFFFF;
      text-align: center;
      color: white;
    }

    .fa-angle-down {
      color: #4D5061;
      position: absolute;
      bottom: 0px;
    }

    .fa-angle-up {
      color: #4D5061;
      position: absolute;
      bottom: 0px;
    }

    .footer {
      height: 6vh;
      background-color: #4D5061;
      padding: 0;
      right: 0;
      bottom: 0;
      left: 0;
    }

    .footertext {
      font-size: 14pt;
      color: white;
      font-family: 'Roboto', sans-serif;
      text-align: center;
    }

    .profile.box {
      bottom: 0;
      height: 50%;
      left: 0;
      margin: auto;
      position: absolute;
      right: 0;
      top: 0;
      width: 50%;
    }

    .shape {
      border-radius: 25px;
      display: inline-block;
      background: #4D5061;
      content: url(http://i1126.photobucket.com/albums/l611/ldocherty1/IMG_0730_zpsiz4dqc47.jpg);
      color: white;
      height: 250px;
      margin: auto;
      padding: 3px;
      width: 250px;
    }

    .shape2 {
      background: linear-gradient(35deg, #4D5061, #4D5061);
      border-radius: 85px;
      color: white;
      height: 40px;
      margin: 1% auto;
      opacity: 0.9;
      display: inline-block;
      padding: 0px;
      width: 250px;
    }
    section{min-height:100vh;padding:10vh 0 0;}

  </style>

</head>

<body>
 <nav class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
      <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
        <a class="navbar-brand" href="#"><img src="http://placehold.it/60x60" alt="Your Brand Name"></a>
        <h1 class="nav-title">Liam Docherty's Digital Portfolio</h1>
      </div>
      <!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav">
          <li><a href="#">Home</a>
          </li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">About Me <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">Action</a>
              </li>
              <li><a href="#section3">Contact</a>
              </li>
              <li><a href="#">Something else here</a>
              </li>
              <li><a href="#">Separated link</a>
              </li>
              <li><a href="#">One more separated link</a>
              </li>
            </ul>
          </li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Units <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">Action</a>
              </li>
              <li><a href="#">Another action</a>
              </li>
              <li><a href="#">Something else here</a>
              </li>

              <li><a href="#">Separated link</a>
              </li>

              <li><a href="#">One more separated link</a>
              </li>
            </ul>
          </li>
          <li><a href="#">Clients</a>
          </li>
          <li><a href="#contact-me">Contact Me</a>
          </li>
        </ul>
      </div>
      <!-- /.navbar-collapse -->
    </div>
    <!-- /.container-fluid -->
  </nav>


  <section id="section1" class="section1">
    <div class="hero">
      <div class="profile box">
        <div class="shape"></div>
        <div class="shape2">
          <p>kjjjjjjjjjkjjjkkjkj</p>
        </div>
      </div>
    </div>





    <a href="#section2"><i class="fa fa-angle-down" style="font-size:100px;"></i></a>

  </section>
  <section id="section2" class="section2">
<h2>
This is some text
</h2>

    <a href="#contact-me"> <i class="fa fa-angle-down" style="font-size:100px;"></i></a>

  </section>

  <section id="contact-me" class="contact_section section3">


    <a href="#section1"> <i class="fa fa-angle-up" style="font-size:100px;"></i></a>

  </section>
  <script src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA=" crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <footer>
    <div class="footer">
      <h2 class="footertext">Copyright © 2017 Liam Docherty's Site. All rights reserved.</h2>
    </div>
  </footer>

1 个答案:

答案 0 :(得分:1)

使用Fullpage.js可以轻松实现。记住要包含所有资源,当然不要忘记调用jquery脚本。为了说清楚,请看我的例子。

        List<Tuple<string,int,string>> list = new List<Tuple<string,int,string>>();
        list.Add(Tuple.Create<string, int, string>("a",100,"up"));
        list.Add(Tuple.Create<string, int, string>("b",99,"up"));
        list.Add(Tuple.Create<string, int, string>("c",120,"up"));
        list.Add(Tuple.Create<string, int, string>("d",200,"up"));

        list.Add(Tuple.Create<string, int, string>("e",112,"down"));
        list.Add(Tuple.Create<string, int, string>("f",10,"down"));
        list.Add(Tuple.Create<string, int, string>("g",110,"down"));

        var temp=list.ToLookup(x => x.Item3);

        var up = temp["up"].OrderByDescending(a => a.Item2);
        Tuple<string, int, string> lowestUp = up.MinBy(a => a.Item2);

        var down=temp["down"].OrderBy(a => a.Item2);
        Tuple<string, int, string> lowestDown = down.MinBy(a => a.Item2);

        if (lowestDown.Item2 < lowestUp.Item2)
        {
            var result = up.Union(down.Except(new Tuple<string, int, string>[] { lowestDown })).ToList();
            result.Insert(result.Count / 2, lowestDown);
        }
        else
        {
            var result = up.Except(new Tuple<string, int, string>[] { lowestUp }).Union(down).ToList();
            result.Insert(result.Count / 2, lowestUp);
        }
$(document).ready(function() {
	$('#fullpage').fullpage();
});
.one {
  background: #F1E05A;
}

.two {
  background: #563D7C;
}

.three {
  background: #E34C26;
}