学习html的小练习
要求:
1、在屏幕大于800px,520-800px,小于520px下的不同布局
2、使用box-shadow实现图标的背景阴影,以及鼠标移入时背景阴影变化
3、使用transform实现鼠标移入的动画效果
4、使用diasplay实现内容的显示隐藏
效果如下:
代码如下:
html:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>响应式滑动菜单</title>
<link rel="stylesheet" href="css/13-2.css">
<link rel="stylesheet" type="text/css" href="css/default.css"/>
</head>
<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>
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, .6);
text-decoration: none;
}
.nav a:hover{
color: #fff;
}
#imgLogo{
display: none;
}
.nav img {
}
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);
}
/* 大于800 */
@media screen and (min-width: 800px) {
#ulList {
display: flex;
text-align: center;
align-self: center;
}
#ulList>li {
width: 200px;
height: 200px;
transition: all 0.5s;
}
#ulList>li>a {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}
/* 鼠标移出的动画效果 */
#ulList>li>a>span{
transition: all 0.5s;
}
.icon>img {
width: 27px;
height: 27px;
border-radius: 50%;
background-color: rgba(236, 235, 235, 0.308);
/* icon的阴影效果 */
box-shadow: 0 0 1px 10px rgba(236, 235, 235, 0.308);
}
/* 鼠标移上去的效果 */
#ulList>li:hover {
height: 250px;
transition: all 0.5s;
}
#ulList>li:hover .icon {
transform: translateY(-50px);
transition: all 0.5s;
border-radius: 50%;
background-color: rgba(236, 235, 235, 0.07);
box-shadow: 0 0 0px 22px rgba(236, 235, 235, 0.07);
}
#ulList>li:hover a>span:nth-child(2) {
transform: translateY(50px);
transition: all 0.3s;
}
}
/* 520-800的屏幕 */
@media screen and (max-width: 799px) and (min-width:520px) {
#ulList{
display: flex;
flex-wrap: wrap;
}
#ulList>li{
width: 50%;
height:80px;
padding: 0 50px;
}
#ulList li a {
display: flex;
align-items: center;
width: 100%;
height: 100%;
}
.icon{
width: 27px;
height: 27px;
margin-right: 80px;
border-radius: 50%;
background-color: rgba(236, 235, 235, 0.308);
/* icon的阴影效果 */
box-shadow: 0 0 1px 10px rgba(236, 235, 235, 0.308);
}
/* 鼠标移入的效果 */
#ulList li:hover{
opacity: 0.95;
transform: all 0.3s;
}
#ulList li:hover .icon{
border-radius: 50%;
background-color: rgba(236, 235, 235, 0.6);
/* icon的阴影效果 */
box-shadow: 0 0 1px 13px rgba(236, 235, 235, 0.6);
}
}
/* 小于520px */
@media screen and (max-width:519px) {
#imgLogo{
display: block;
}
#ulList{
display: none;
}
#ulList>li>a{
display: flex;
height: 50px;
line-height: 50px;
margin-left: 15px;
background-color: rgb(245, 245, 245,0.15);
}
.icon{
margin: 5px 150px 0 20px;
}
}