css - 未激活但媒体屏幕大小为 600 像素时的菜单按钮位置
问题描述
未激活但媒体屏幕大小为 600 像素时的菜单按钮位置。我有显示我需要它做什么的屏幕截图,我不担心菜单的外观,但是在调整媒体屏幕大小后,我一直遇到菜单按钮不在我想要的位置的问题。
我希望菜单按钮在单击它之后的位置,但它不能按我想要的方式工作。
截图:
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: inline-block;
}
}
@media screen and (max-width: 600px) {
.topnav.responsive {position: relative;}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: center;
}
}
在此先感谢您,感谢您的帮助。
解决方案
请尝试此代码
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
body {
font-family: Arial, Helvetica, sans-serif;
text-align: center; padding:0; margin:0;
}
.imglogo {
float: inherit;
width: 250px;
height: 67px;
background: url(img/logo.png) no-repeat center;
display: block;
}
.topnav {
overflow: hidden;
background-color: #333;
box-shadow: 0px 5px 5px grey;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.active {
background-color: #86cc53;
color: white;
}
.transbox {
background-color: #86cc53;
border-radius: 5px;
border: 1px solid black;
opacity: 0.6;
filter: alpha(opacity=60); /* For IE8 and earlier */
}
.topnav .icon {
display: none;
}
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: inline-block;
position: absolute;
top: 10px;
right: 10px;
}
.topnav.responsive {position: absolute; left:0; right: 0; top:0;}
.topnav.responsive .icon {
position: absolute;
}
.topnav.responsive a {
float: none;
display: block;
text-align: center;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="topnav" id="myTopnav">
<i class="imglogo"></i>
<a href="javascript:void(0);" class="icon" onClick="myFunction()">
<i class="fa fa-bars"></i>
</a>
<a href="#home" class="active">Home</a>
<a href="#news">Services</a>
<a href="#contact">Contact</a>
<a href="#about" class="transbox">About</a>
</div>
<div>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<h2>This Site is Under Construction.</h2>
<p>In need of any computer, networking repair/setup/configuraion or consulting contact my cell leave a message for NICK. CELL:xxx-xxx-xxx</p>
</div>
推荐阅读
- ubuntu - 如何杀死在 Windows、Linux 和 MacOS 中特定端口上运行的进程 - C# (.Net Core)
- tableview - JavaFX8 - 自定义的 EditCell 类 - 如何禁用 TableView 的鼠标单击,同时仍然允许在正在编辑的 TableCell 内单击?
- python - Keras 没有使用完整的 CPU 内核进行训练
- react-native - 如何在反应natvie中滚动到滚动视图的开头
- python-3.x - 如何将存储在 YYYYMMDD 中的日期转换为 pandas 中的日期时间格式
- knockout.js - 淘汰赛绑定后如何访问DOM元素?
- python - NumPy 数组的滚动/增加维度
- javascript - Angular5:window.addEventListener 卡住浏览器选项卡
- c - 如何在单线程服务器上处理多个客户端(使用套接字)
- plone - 删除 Plone 错误页面上的 HTTP 标头