<!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: #0dc1d8;
}
.one>li{
width: 20%;
line-height: 40px;
text-align: center;
float: left;
overflow: hidden;
}
.two{
/* display: none; */
transform: translateY(-250px);
position: relative;
z-index: -1;
}
.one>li:hover .two{
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{
width: 100px;
height: 300px;
top: 0;
background-color: blanchedalmond;
position: absolute;
left: 300px;
transform: translateX(-100px);
z-index: -1;
}
.one>li:hover .two{
transform: translateX(0);
transition: 0.5s;
}
}
小屏样式
@media screen and (max-width:768px) {
.one{
width: 100%;
}
.one li{
width: 100%;
height: 40px;
text-align: center;
line-height: 40px;
background-color: aqua;
}
.two{
width: 100%;
height: 200px;
/* background-color: yellow; */
position: relative;
z-index: -1;
transform: translateY(-200px);
}
.one>li:hover .two{
z-index: 5;
transform: translateY(-0px);
transition: 0.3s;
}
}
</style>
</head>
<body>
<ul class="one">
<li>1613</li>
<li>9634</li>
<li>45174
<ul class="two">
<li>1613</li>
<li>9634</li>
<li>45174</li>
<li>5744</li>
<li>7845</li>
</ul>
</li>
<li>5744</li>
<li>7845</li>
</ul>
</body>
</html>
效果图
大屏效果 中屏效果 小屏效果