<!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;
}
ul li {
list-style: none;
}
/* 大屏 */
@media screen and (min-width:1200px){
.one{
width: 80%;
margin: 50px auto;
height: 40px;
background-color: rgb(73, 197, 156);
}
.one>li{
float: left;
width: 20%;
line-height: 40px;
text-align: center;
overflow: hidden;
}
.two{
/* display: none; */
/* position: relative; */
transform: translateY(-250px);
z-index: -1;
}
.two li{
background-color: aqua;
}
.one>li:hover .two{
display: block;
transform: translateY(0);
transition: 0.5s;
}
}
@media screen and (min-width:768px) and (max-width:1200px){
.one{
width: 300px;
height: 400px;
background-color: aqua;
}
.one>li{
width: 100%;
height: 50px;
text-align: center;
line-height: 50px;
position: relative;
}
.two{
position: absolute;
left: 300px;
width: 100px;
top: 0;
background-color: blanchedalmond;
height: 300px;
transform: translate(-100px,-20PX);
z-index: -1;
}
.one>li:hover .two{
transform: translate(0,20PX);
transition: 0.5s;
}
}
@media screen and (max-width:768px){
.one{
width: 100%;
}
.one li{
width: 100%;
text-align: center;
height: 40px;
line-height: 40px;
background-color: rgb(40, 190, 177);
}
.two{
width: 100%;
height: 200px;
position: relative;
z-index: -1;
transform: translateY(-250px);
}
.one>li:hover .two{
transform: translateY(0px);
transition: 0.3s;
z-index: 5;
}
}
</style>
</head>
<body>
<ul class="one">
<li>首页</li>
<li>22</li>
<li>咨询
<ul class="two">
<li>1</li>
<li>2</li>
<li>1</li>
<li>1</li>
<li>1</li>
</ul>
</li>
<li>售后</li>
<li>客服</li>
</ul>
</body>
</html>
响应式布局:根据屏幕大小,显示合适的内容。
响应式开发的原理是使用CSS3中的Media Query(媒体查询)针对不同宽度的设备设置不同的布局和样式,从而适配不同的设备。
CSS3 @media 查询定义和使用:
使用 @media 查询,你可以针对不同的媒体类型定义不同的样式。@media 可以针对不同的屏幕尺寸设置不同的样式,特别是如果你需要设置设计响应式的页面,@media 是非常有用的。当你重置浏览器大小的过程中,页面也会根据浏览器的宽度和高度重新渲染页面。