【发布时间】:2018-06-02 05:12:42
【问题描述】:
我有一些导航 html,我正在尝试使其具有响应性。我已经成功地让汉堡菜单出现在小于 1050 像素的屏幕尺寸上,并且它可以打开和关闭菜单。问题是,如果在放大屏幕之前不关闭汉堡菜单,导航菜单就会卡在 display: none 模式并且不显示。所以看起来导航突然不见了。我认为普通的 css 会在更大的屏幕尺寸下使用,但可能是因为该属性是在脚本中设置的,所以它会徘徊。谁能帮我解决这个问题。我对响应式设计相当陌生。
html:
<nav>
<div class="navigation">
<a href="/index.html"> <img class="nav-img" src="/incl/image.png"> </a>
<button id="mobile" type="button" onclick="toggleFunction()">
<img src="/incl/menu.png" width="35px" height="35px" alt="menu">
</button>
<ul id="nav-list">
<li> <a href="/proposer/">Proposer</a> </li>
<li> <a href="/cda/">Archive</a> </li>
<li> <a href="/ciao/">Data<br/>Analysis</a> </li>
<li> <a href="/cal/">Instruments and<br/>Calibration</a> </li>
<li> <a href="/public/">For The<br/>Public</a> </li>
</ul>
</div></nav>
<script>
function toggleFunction() {
var x = document.getElementById('nav-list');
if (x.style.display === 'block') {
x.style.display = 'none';
} else {
x.style.display = 'block';
}
}
</script>
css:
#nav-list {
list-style-type: none;
padding-top: 30px;
padding-right: 20px;
margin: 0px;
overflow: hidden;
display: inline-table;
float: right;
}
#nav-list li {
display: table-cell;
vertical-align: middle;
padding: 0px 15px;
margin: 0px;
text-align: center;
line-height: 110%;
font-size: 1.3em;
font-family: Helvetica, Arial, sans-serif;
font-weight: 400;
}
#mobile {
display: none;
}
@media only screen and (max-width: 1050px) {
.nav-img {
margin: 0px 5px 5px 5px;
}
#mobile {
display: inline;
float: right;
background-color: transparent;
border: 1px solid #333;
border-radius: 5px;
margin: 10px 10px 10px 0px;
padding: 5px;
}
#nav-list {
list-style-type: none;
margin: 0px;
padding: 0px;
overflow: hidden;
display: none;
float: none
}
#nav-list li {
display: block;
text-align: center;
margin: 10px 0px 10px 0px;
line-height: 110%;
font-size: 1em;
}
【问题讨论】:
标签: javascript jquery html css responsive-design