我正在尝试从移动设备的顶部创建滑动导航,但是我无法弄清楚为什么滑动导航位于标题的顶部。我希望标题始终在最前面,并且我尝试了z-index和position:绝对,但是并不能解决问题。
代码:https://codepen.io/alexisvilaca/pen/XqmJmo
的HTML
<!-- Navigation -->
<nav class="topHeader clearfix">
<div class="headerWrapper">
<div class="logo">
<a href="#">Logo</a>
</div>
<div class="navigation">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div>
<div class="hamburgerMenu">
<a href="#">
<span></span>
<span></span>
<span></span>
</a>
</div>
<div class="hamburgerNavigation">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div>
</div>
</nav>
萨斯
$white: #ffffff
$black: #000000
$highlight: blue
// Navigation
*
margin: 0
padding: 0
.clearfix::after
content: ""
clear: both
display: table
// Navigation
.topHeader
width: 100%
padding: 50px 0
@media only screen and (max-width:768px)
padding: 20px 0
background-color: #dddddd
.headerWrapper
width: 90%
margin: 0 auto
.logo
width: 100px
float: left
@media only screen and (max-width:768px)
width: 80px
.navigation
float: right
font-size: 1.125em
padding-top: 16px
@media only screen and (max-width:768px)
display: none
a
color: $black
text-decoration: none
margin-left: 2em
transition: 0.2s ease-in-out
&:hover
color: $highlight
.hamburgerMenu
cursor: pointer
display: none
margin-top: 8px
@media only screen and (max-width: 768px)
display: block
float: right
span
display: block
width: 25px
height: 3px
margin: 5px 0
border-radius: 5px
background-color: $black
transform-origin: left center
transition: 0.2s ease-in-out
.open
span
&:nth-child(1)
transform: rotate(45deg) translate(0px, 0px)
&:nth-child(2)
opacity: 0
transform: translateX(-10px)
&:nth-child(3)
transform: rotate(-45deg) translate(-1px, 1px)
.hamburgerNavigation
left: 0
top: 0
display: none
width: 100vw
height: 100vh
background-color: $black
position: fixed
opacity: 0
transform: translate3d(0, -100vh, 0)
transition: 0.2s ease-in-out
@media only screen and (max-width:768px)
display: flex
align-items: center
justify-content: center
flex-flow: column
a
color: $white
text-decoration: none
font-size: 1.125em
margin: 15px 0
.show
opacity: 1
transform: translate3d(0, 0vh, 0)
JAVASCRIPT
$(document).ready(function(){
$('.hamburgerMenu').click(function(){
$(this).toggleClass('open');
});
});
$('.hamburgerMenu').click( function() {
$(".hamburgerNavigation").toggleClass("show");
} );
最佳答案
您可以将top
设置为.topHeader
.topHeader .headerWrapper .show {
opacity: 1;
transform: translate3d(0, 0vh, 0);
top: 77px; // Added
}
或者您可以设置负数
z-index
.topHeader .headerWrapper .show {
opacity: 1;
transform: translate3d(0, 0vh, 0);
z-index: -1; // Added
}
关于html - 在标题上方滑动移动导航,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49956273/