<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.nav-logo{
float: left;
line-height: 40px;
width: 100px;
}
.nav{
float: right;
/* background-color: red; */
}
.nav ul{
float: left;
}
.nav li{
float: left;
width: 100px;
line-height: 40px;
text-align: center;
}
@media screen and (max-width:800px) {
.nav-logo{
float: none;
}
.nav-logo span{
display: inline-block;
width: 40px;
height: 40px;
background-color: red;
position: absolute;
top: 0;
right: 0;
}
.nav{
float: none;
margin-left: -200%;
}
.nav ul{
text-align: center;
float: none;
}
.nav li{
float: none;
width: 100%;
line-height: 40px;
text-align: center;
}
}
</style>
</head>
<body>
<div cla="nav-box">
<div class="nav-logo">
我是logo
<span onclick="btn()"></span>
</div>
<nav class="nav" id='nav'>
<ul>
<li>
首页aa
</li>
<li>
产品列表
</li>
<li>
服务咨询
</li>
<li>
关于我们
</li>
<li>
联系我们
</li>
</ul>
</nav>
</div>
</body>
<script>
var nums= 0;
function btn(){
nums++;
var navs = document.getElementById('nav');
navs.style.transition = '1s';
if(nums%2==1){
navs.style.marginLeft = '0';
navs.style.background = 'blue';
}else{
navs.style.marginLeft = '-200%';
navs.style.background = '';
}
}
</script>
</html>
Last modification:November 28, 2020
© Allow specification reprint