我设置@media (max-width: 820px)在pc页面小于820也无效 在移动端才有效
来源:4-4 自由编程
WebSaber
2019-10-14 21:29:50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{
list-style: none;
padding: 0;
margin: 0;
box-sizing: border-box;
}
header{
height: 100px;
width: 100%;
border-bottom: 1px solid gray;
display: flex;
align-items: center;
position: relative;
overflow: hidden;
}
header ul{
display: flex;
position: absolute;
left: 0;
}
header ul li{
margin-left: 50px;
}
header img{
margin: 0 auto;
width: auto;
height: 100px;
}
header div{
height: 200px;
width: 200px;
background: red;
border-radius: 50%;
color: #fff;
position: absolute;
left: -100px;
bottom: -100px;
display: none;
}
header div b{
height: 0;
width: 40px;
border: 1px #fff solid;
position: absolute;
right: 50px;
top: 50px;
}
header div b:last-child{
top: 70px;
}
.none{
width: 100%;
height: 0px;
background: rgb(201, 200, 200);
overflow: hidden;
position: relative;
top: -1px;
transition: height 0.5s;
}
.text-none{
height: 151px;
top: 0px;
}
.none ul li{
width: 100%;
line-height: 50px;
border-bottom: 1px solid gray;
padding-left: 30px;
}
@media (max-width: 820px){
header ul{
display: none;
}
header div{
display: block;
}
}
</style>
</head>
<body>
<header>
<div>
<b></b><b></b>
</div>
<ul>
<li>首页</li>
<li>关于</li>
<li>商业合作</li>
</ul>
<img src="https://www.imooc.com/static/img/index/logo.png" alt="logo">
</header>
<div class="none" id="none">
<ul>
<li>首页</li>
<li>关于</li>
<li>商业合作</li>
</ul>
</div>
<script>
var div=document.getElementsByTagName("div")[0];
var none=document.getElementById("none");
div.onclick=function(){
if(none.classList.contains("text-none")){
none.classList.remove("text-none");
}else{
none.classList.add("text-none");
}
}
</script>
</body>
</html>2回答
同学你好,
老师这边使用Chrome浏览器测试效果没有问题,在PC端820px以下是可以实现效果的,如下:

题目中要求中屏一下,可以修改一下条件哦:

祝学习愉快!
好帮手慕星星
2019-10-15
你好,老师上一次给你截图中可以看到宽度为819px:

达到媒体查询设置的宽度就可以了,不是到400px。同学是用哪个浏览器进行测试的呢,建议具体描述一下,便于准确定位问题所在。
祝学习愉快!
相似问题