当我打开菜单时它是一样的。如果我以较小的分辨率打开菜单,它会在较大的屏幕上显示我的菜单。看起来我的.expand类无论屏幕分辨率是多少都没有,并且不会默认为我的媒体查询设置。
我该如何解决这个问题?这是我的代码,我使用post css与mixins(scss和媒体查询),以及用于JS的ES6类(有点非正统我想但是试验)
CSS
.primary-nav {
position: relative;
font-size: 1rem;
top: 0;
left: 0;
-webkit-transform: translate(0,-10%);
transform: translate(0,-10%);
display: none;
}
@media (min-width: 340px) {
.primary-nav .expand {
display: block;
}
}
@media (min-width: 650px) {
.primary-nav {
display: none;
font-size: 1rem;
top: 0;
left: 0;
-webkit-transform: translate(0,-10%);
transform: translate(0,-10%)
}
.primary-nav .expand {
display: block;
}
}
@media (min-width: 1200px) {
.primary-nav {
display: block;
font-size: 1rem;
height: 5vh;
top: 0;
left: 4rem
}
}
@media (min-width: 1920px) {
.primary-nav {
font-size: 1.2rem;
height: 7vh;
display: block;
top: 1rem;
left: 0;
padding: 1rem
}
}
.primary-nav ul {
margin: 0;
text-align: center;
width: 100%;
padding: 0;
}
@media (min-width: 1200px) {
.primary-nav ul {
padding: 0
}
}
.primary-nav li {
display: block;
border-bottom: 1px solid #FF00A2;
}
@media (min-width: 1200px) {
.primary-nav li {
display: inline;
padding-left: 2%;
border-bottom: none
}
}
@media (min-width: 1920px) {
.primary-nav li {
padding-left: 5%
}
}
.primary-nav li:last-child {
border-bottom: none;
}
.primary-nav a {
text-decoration: none;
color: rgb(46, 198, 218);
display: inline-block;
padding: 5px;
}
@media (min-width: 650px) {
.primary-nav a {
padding: 8px
}
}
//postcss with mixins
.primary-nav {
position: relative;
font-size: 1rem;
top: 0;
left: 0;
transform: translate(0,-10%);
display: none;
.expand {
display: block;
}
@mixin atMedium {
display: none;
font-size: 1rem;
top: 0;
left: 0;
transform: translate(0,-10%);
}
@mixin atLarge {
display: block;
font-size: 1rem;
height: 5vh;
top: 0;
left: 4rem;
}
@mixin atXLarge {
font-size: 1.2rem;
height: 7vh;
display: block;
top: 1rem;
left: 0;
padding: 1rem;
}
ul {
margin: 0;
text-align: center;
width: 100%;
padding: 0;
@mixin atLarge {
padding: 0;
}
}
li {
display: block;
border-bottom: 1px solid $hotPink;
@mixin atLarge {
display: inline;
padding-left: 2%;
border-bottom: none;
}
@mixin atXLarge {
padding-left: 5%;
}
}
li:last-child {
border-bottom: none;
}
a {
text-decoration: none;
color: $mainTeal;
display: inline-block;
padding: 5px;
@mixin atMedium {
padding: 8px;
}
}
}
JS
import $ from 'jquery';
class MobileMenu {
// dom selection usually and firing events when a page loads.
constructor(){
this.menuButton = $('.mobile-menu');
this.events();
}
//events to watch for such as click
events(){
this.menuButton.on('click', function(){
$('.primary-nav').slideToggle(400, function() {
$(this).toggleClass('.expand');
// console.log('hello');
});
});
}
}
export default MobileMenu;
HTML
<span class="mobile-menu">
<i class="fas fa-bars"></i>
</span>
<nav class="primary-nav col col--md-8 col--lg-8">
<ul>
<li><a href="#hero">Project How To</a></li>
<li><a href="#faq" >Rules/Terms</a></li>
<li><a href="#blog" >Blog</a></li>
<li><a href="#account">My Account</a></li>
<li><a href="#log" >Log In</a></li>
<li><a href="#"><i class="icons icons--cart fas fa-shopping-cart "></i></a></li>
</ul>
</nav>
原谅定位,我的导航菜单附近有一个标识,我必须相应调整。