这个问题可能很愚蠢,甚至我花了近一个小时在stackoverflow上浏览过去的问题,又花了一个小时在google上看我是否可以找到解决方案,但我失败了。
问题是我的“媒体查询”根本没有用。
这是我的Codepen版本:https://codepen.io/anon/pen/WaXpda
这里是stackoverflow版本:
.header-menu-toggle {
position: fixed;
left: 12px;
top: 12px;
width: 48px;
height: 45px;
line-height: 45px;
font-family: 'Exo', sans-serif;
font-size: 1.2rem;
text-transform: uppercase;
letter-spacing: 0.4rem;
color: black;
-webkit-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
.header-menu-toggle::after {
display: inline-block;
content: "Menu";
height: 45px;
left: 35px;
text-align: right;
padding-left: 15px;
padding-right: 10px;
position: absolute;
top: 0;
right: 100%;
}
.header-menu-toggle:hover, .header-menu-toggle:focus {
color: #CC147C;
}
.header-menu-icon {
display: block;
width: 26px;
height: 2px;
margin-top: -1px;
right: auto;
bottom: auto;
background-color: black;
position: absolute;
left: 11px;
top: 50%;
}
.header-menu-icon::before, .header-menu-icon::after {
content: "";
width: 100%;
height: 100%;
background-color: inherit;
position: absolute;
left: 0;
}
.header-menu-icon::before {
top: -9px;
}
.header-menu-icon::after {
bottom: -9px;
}
@media screen and(max-width:768px){
.header-menu-toggle{
left:300px; /*middle, just for testing*/
}
}
<div id="firstPage" class="firstPage">
<a onclick="openNav()" class="header-menu-toggle" href="#0">
<span class="header-menu-icon"></span>
</a>
</div>
问题是,当屏幕宽度小于768px时,应将菜单文本移到中间。但是,这没有发生,我尝试过重新设置颜色,并且它们工作正常。只是定位不是。
非常感谢您花时间回答这个问题,甚至是阅读它。
答案 0 :(得分:1)
语法错误。
您在查询中缺少空格
.header-menu-toggle {
position: fixed;
left: 12px;
top: 12px;
width: 48px;
height: 45px;
line-height: 45px;
font-family: 'Exo', sans-serif;
font-size: 1.2rem;
text-transform: uppercase;
letter-spacing: 0.4rem;
color: black;
-webkit-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
.header-menu-toggle::after {
display: inline-block;
content: "Menu";
height: 45px;
left: 35px;
text-align: right;
padding-left: 15px;
padding-right: 10px;
position: absolute;
top: 0;
right: 100%;
}
.header-menu-toggle:hover, .header-menu-toggle:focus {
color: #CC147C;
}
.header-menu-icon {
display: block;
width: 26px;
height: 2px;
margin-top: -1px;
right: auto;
bottom: auto;
background-color: black;
position: absolute;
left: 11px;
top: 50%;
}
.header-menu-icon::before, .header-menu-icon::after {
content: "";
width: 100%;
height: 100%;
background-color: inherit;
position: absolute;
left: 0;
}
.header-menu-icon::before {
top: -9px;
}
.header-menu-icon::after {
bottom: -9px;
}
@media all and (max-width:768px){
.header-menu-toggle{
left:300px; /*middle, just for testing*/
}
}
<div id="firstPage" class="firstPage">
<a onclick="openNav()" class="header-menu-toggle" href="#0">
<span class="header-menu-icon"></span>
</a>
</div>
PS。抱歉,浪费了2个小时:(