【发布时间】:2017-10-16 23:41:27
【问题描述】:
我需要帮助设置 Bootstrap 的 Scrollspy。我遵循了文档中的指导方针,但没有奏效。请帮我找到解决这个问题的方法
我在 body 元素中使用数据属性并将位置设置为相对 这是我的 HTML 代码:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
<link href="https://fonts.googleapis.com/css?family=Fascinate+Inline|Anton|Raleway:200|Megrim" rel="stylesheet">
<style>
body {
height: 100vh;
background: url("https://image.ibb.co/i1Qu1R/Adobe_Stock_123146928.png") no-repeat fixed;
background-size: cover;
position: relative;
top: 121px;
}
.active {
color: black !important;
</style>
<nav id="main-nav" class="nav justify-content-end fixed-top">
<!-- nav-fill nav-justified flex-column flex-md-row-->
<a href="#" class="navbar-brand">marouane <span>rassili</span></a>
<a href="#home" class="nav-link home active">
<!-- flex-md-fill text-md-center"-->Home</a>
<a href="#gallery" class="nav-link gallery">
<!-- flex-md-fill text-md-center"-->Gallery</a>
<a href="#about" class="nav-link about">
<!-- flex-md-fill text-md-center"-->About</a>
<a href="#contact" class="nav-link contact">
<!-- flex-md-fill text-md-center"-->Contact</a>
</nav>
<body data-spy="scroll" data-target="#main-nav">
<section id="home">
<div class="text-center">
<h1>HOME</h1>
</div>
</section>
<section id="gallery">
<div class="text-center">
<h1>GALLERY</h1>
</div>
</section>
<section id="about">
<div class="text-center">
<h1>ABOUT ME</h1>
</div>
</section>
<section id="contact">
<div class="text-center">
<h1>CONTACT ME</h1>
</div>
</section>
(我正在使用 Codepen)
【问题讨论】:
标签: twitter-bootstrap bootstrap-4 scrollspy