Html 如何将导航链接放置到右侧并在其上应用scrollspy?
我正在制作一个投资组合,但在使用Bootstrap 4时遇到了两个问题:Html 如何将导航链接放置到右侧并在其上应用scrollspy?,html,css,twitter-bootstrap,Html,Css,Twitter Bootstrap,我正在制作一个投资组合,但在使用Bootstrap 4时遇到了两个问题: 将导航栏链接放置到右侧 还有,引导程序 有人能帮我解决以上两个问题吗 我已经尝试过Bootstrap和w3schools站点上的代码,但是没有任何效果 下面是我的代码: CSS代码: body { scroll-behavior: smooth; font-family: "Spectral", sans-serif; height: 100%; position: relative;
body {
scroll-behavior: smooth;
font-family: "Spectral", sans-serif;
height: 100%;
position: relative;
background: linear-gradient(90deg, #ffffff 50%, #ffd600 50%);
}
nav ul li a {
font-weight: bold;
font-size: 20px;
text-decoration: underline;
text-underline-position: under !important;
margin-right: 12px;
}
HTML代码:
<body data-spy="scroll" data-target="#mainNav" data-offset="0">
<div class="main">
<nav class="navbar navbar-expand-lg fixed-top" id="mainNav">
<button
class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link" href="#homeSection">Home</a></li>
<li class="nav-item"><a class="nav-link" href="#aboutSection">About</a></li>
<li class="nav-item"><a class="nav-link" href="#skillSection">Skills</a></li>
<li class="nav-item"><a class="nav-link" href="#workSection">Works</a></li>
<li class="nav-item"><a class="nav-link" href="#contactSection">Contact</a></li>
</ul>
</div>
</nav>
<main id="fullpage">
<section id="homeSection" class="section">.....</section>
<section id="aboutSection" class="section">.....</section>
<section id="skillSection" class="section">.....</section>
<section id="workSection" class="section">.....</section>
<section id="contactSection" class="section">.....</section>
</main>
</div>
</body>
.....
.....
.....
.....
.....
请尝试此代码
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<style>
body {
position: relative;
}
</style>
</head>
<body data-spy="scroll" data-target=".navbar" data-offset="50">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
<ul class="navbar-nav d-flex ml-auto">
<li class="nav-item">
<a class="nav-link" href="#section1">Section 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#section2">Section 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#section3">Section 3</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
Section 4
</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#section41">Link 1</a>
<a class="dropdown-item" href="#section42">Link 2</a>
</div>
</li>
</ul>
</nav>
<div id="section1" class="container-fluid bg-success" style="padding-top:70px;padding-bottom:70px">
<h1>Section 1</h1>
<p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
<p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
</div>
<div id="section2" class="container-fluid bg-warning" style="padding-top:70px;padding-bottom:70px">
<h1>Section 2</h1>
<p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
<p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
</div>
<div id="section3" class="container-fluid bg-secondary" style="padding-top:70px;padding-bottom:70px">
<h1>Section 3</h1>
<p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
<p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
</div>
<div id="section41" class="container-fluid bg-danger" style="padding-top:70px;padding-bottom:70px">
<h1>Section 4 Submenu 1</h1>
<p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
<p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
</div>
<div id="section42" class="container-fluid bg-info" style="padding-top:70px;padding-bottom:70px">
<h1>Section 4 Submenu 2</h1>
<p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
<p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
</div>
</body>
</html>
引导示例
身体{
位置:相对位置;
}
-
-
-
-
第一节
尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏
尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏
第二节
尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏
尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏
第三节
尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏
尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏
第4节子菜单1
尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏
尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏
第4节子菜单2
尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏
尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏
以上我的代码工作得很好。那么为什么你被否决了呢?有些用户不喜欢除了显示工作代码之外,不试图解释为什么他们是解决方案的解决方案。