【发布时间】:2019-05-09 11:50:46
【问题描述】:
初始加载:
滚动后:
我试图在视口顶部有一个固定的导航。因此,当您向下滚动页面时,导航始终可见。我的问题是我的导航栏品牌设置在导航的左侧,而指向页面其余部分的链接设置在右侧。当我将位置固定添加到导航栏品牌时,它工作正常(当我向下滚动页面时,品牌保持可见),但是当我将位置固定添加到任何其他类、id 或涉及链接的元素时,无论我尝试了什么设置在右侧,它们最终会固定在左侧并覆盖品牌或直接位于品牌下方。我无法弄清楚为什么会这样。
我尝试在导航栏中添加固定到各种类的位置,但没有成功。我还尝试使用 float:right!important 将项目强制向右移动。我发现的大多数文章都建议添加 position: fixed 到 .nav 类,但是当我这样做时,这些项目被推到左边。我在导航中包含了 html 以及导航的 CSS、背景视频和我在导航中链接到的模式,以防万一这可能导致问题。谢谢你的帮助!非常感谢。
HTML
<nav class="navbar">
<div class="container-fluid">
<div class="navbar-header">
<a href="#home"><h3>allicndev</h3></a>
</div><!-- /navbar-header -->
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#about" class="db-line">About</a></li>
<li class="active"><a href="#portfolio">Portfolio</a></li>
<li class="active">
<!-- <a href="#" data-toggle="modal" data-placement="top" title="Resume" data-target="#modalResume"><span>Resume</span></a> -->
<a href="#" data-toggle="modal" data-target="#myModal">Resume</a>
</li>
<li class="active"><a href="#skills">Skills</a></li>
<li class="active"><a href="#contact">Contact</a></li>
</ul><!-- /nav navbar-nav navbar-right -->
</div><!-- /container-fluid -->
</nav>
<!-- /navigation -->
<!-- modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">X</button>
<h4 id="myModalLabel" class="modal-title">Resume</h4>
</div><!-- /modal-header -->
<div class="modal-content">
<embed id="modal-embed" src="assets/anresume.pdf">
</div><!-- /modal-content -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div><!-- /modal-footer -->
</div><!-- /modal fade -->
<!-- /modal -->
CSS
* {
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
overflow-x: hidden;
position: relative;
}
body {
margin: 0;
font-family: 'Montserrat', Arial, sans-serif;
font-size: 17px;
}
#myVideo {
position: absolute;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
}
.container-fluid {
padding-right: 30px;
/* position: fixed; */
}
nav {
height: 75px;
display: border-box;
color: white;
font-size: 12px;
text-align: center;
position: fixed;
/*z-index: 10px;*/
}
nav.navbar {
width: 100%;
}
.navbar-header {
position: fixed;
}
.nav.navbar-nav.navbar-right > li {
padding-top: 15px;
margin: 10px;
}
.nav > li > a {
display: inline;
padding-left: 0;
padding-right: 0;
padding-top: 5px;
background-color: transparent;
}
.navbar-nav>.active>a, .navbar-nav>.active>a:focus, .navbar-nav>.active>a:hover {
background-color: transparent;
}
a.db-line {
transition: white .3s linear;
}
a {
color: white;
text-decoration: none;
}
a > h3 {
color: white;
text-decoration: none;
}
a:hover {
color: #f97f04;
}
/* a:visited {
color: #EDCF10;
} */
.modal {
display: none;
height: 100%;
left: 10px;
position: fixed;
top: 0;
width: 100%;
}
.modal.open {
display: block;
}
.modal-header,
.modal-footer {
height: 75px;
}
.modal-content,
.modal-footer {
width: 100%;
}
.modal-footer {
bottom: 0px;
}
#modal-embed {
width: 100%;
height: 75vh;
}
如果可能的话,我希望品牌(“allicndev”)位于左上方,链接(“about”、“portfolio”、“resume”、“skills”和“contact”)位于右侧顶部和整个导航在页面滚动或点击指向部分的链接时保持可见。
【问题讨论】:
标签: html css bootstrap-4 navbar