<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>响应式滑动菜单</title>
<link rel="stylesheet" type="text/css" href="css/default.css" />
</head>
<style>
.main {
width: 1000px;
}
#ulList {
display: flex;
width: 100%;
}
ul li {
transition: all .3s;
}
a::after {
position: absolute;
left: 0;
top: 0;
content: '';
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .2);
z-index: 999;
}
li a {
position: relative;
display: flex !important;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
transition: all .5s;
}
.icon {
display: flex !important;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
border-radius: 100%;
background-color: rgb(209, 206, 206, .5);
box-shadow: 0 0 30px 30px transparent;
transition: all .5s ease-in-out;
}
li:hover .icon {
box-shadow: 0 0 0px 0px rgba(238, 235, 235, 0.5);
}
li:hover a {
justify-content: space-around;
}
#ulList li:hover a::after {
z-index: -99;
}
@media screen and (min-width:520px) and (max-width:799px) {
ul li {
width: 50%;
height: 100px;
}
li a {
flex-direction: row;
justify-content: space-between;
padding: 0 50px;
}
#ulList li:hover {
height: 150px;
}
#ulList {
display: flex !important;
flex-wrap: wrap;
width: 700px;
}
}
@media screen and (max-width:519px) {
#ulList {
flex-direction: column;
width: 350px;
}
ul li {
height: 50px;
}
li a {
flex-direction: row;
justify-content: space-between;
padding: 0 50px;
}
.icon {
width: 30px;
height: 30px;
}
#imgLogo {
display: block;
}
#ulList {
display: none;
}
}
@media screen and (min-width:800px) {
ul li {
display: flex;
flex: 1;
height: 200px;
}
#ulList li:hover {
height: 250px;
}
#ulList {
display: flex !important;
width: 100%;
}
}
</style>
<body>
<div class="container">
<header>
<h1>响应式滑动菜单</h1>
</header>
<div class="main clearfix">
<nav id="menu" class="nav">
<img id="imgLogo" src="images/1.png" alt="" />
<ul id="ulList">
<li>
<a href="#">
<span class="icon">
<img src="images/2.png" alt="" />
</span>
<span>Home</span>
</a>
</li>
<li>
<a href="#">
<span class="icon">
<img src="images/3.png" alt="" />
</span>
<span>Services</span>
</a>
</li>
<li>
<a href="#">
<span class="icon">
<img src="images/4.png" alt="" />
</span>
<span>Portfolio</span>
</a>
</li>
<li>
<a href="#">
<span class="icon">
<img src="images/5.png" alt="" />
</span>
<span>Blog</span>
</a>
</li>
<li>
<a href="#">
<span class="icon">
<img src="images/6.png" alt="" />
</span>
<span>The team</span>
</a>
</li>
<li>
<a href="#">
<span class="icon">
<img src="images/7.png" alt="" />
</span>
<span>Contact</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
<script src="js/jquery-1.12.4.js"></script>
<script>
$('#imgLogo').click(function () {
$('#ulList').toggle();
})
</script>
</body>
</html>
default.css
*, *:after, *:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body, html {
font-size: 15px;
padding: 0;
margin: 0;
}
.clearfix:after {
content: " ";
display: block;
clear: both;
}
body {
font-family: 'Lato', Calibri, Arial, sans-serif;
color: #89867e;
background: #f9f9f9;
}
a {
color: #333;
text-decoration: none;
}
a:hover {
color: #fff;
}
.main, .container > header {
width: 100%;
margin: 0 auto;
padding: 30px;
}
.main {
max-width: 1024px;
min-height: 600px;
}
.container > header {
text-align: center;
font-size: 16px;
background: rgba(0, 0, 0, 0.01);
}
.container > header h1 {
font-size: 30px;
line-height: 1.3;
margin: 0;
font-weight: normal;
}
.nav ul {
max-width: 1240px;
margin: 0;
padding: 0;
list-style: none;
font-size: 24px;
font-weight: 300;
}
.nav li span {
display: block;
}
.nav a {
display: block;
color: rgba(249, 249, 249, .9);
text-decoration: none;
}
#imgLogo{
display: none;
}
a, button {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
.nav li:nth-child(6n+1) {
background: rgb(208, 101, 3);
}
.nav li:nth-child(6n+2) {
background: rgb(233, 147, 26);
}
.nav li:nth-child(6n+3) {
background: rgb(22, 145, 190);
}
.nav li:nth-child(6n+4) {
background: rgb(22, 107, 162);
}
.nav li:nth-child(6n+5) {
background: rgb(27, 54, 71);
}
.nav li:nth-child(6n+6) {
background: rgb(21, 40, 54);
}