响应式布局(媒体查询)
【摘要】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name...
<!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 type="text/css">
*{padding: 0px;margin: 0px;}
body
{
transition: 0.3s;
}
@media all and (max-width: 900px)
{
body
{
background: red;
}
}
@media all and (min-width: 900px) and (max-width: 1200px)
{
body
{
background: yellow;
}
}
@media all and (min-width: 1200px)
{
body
{
background: black;
}
}
</style>
</head>
<body>
</body>
</html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
数字>=1200变成黑色.
900<=数字 <=1200.变成黄色.
数字<=900就红色.
<!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 type="text/css">
*{padding: 0px;margin: 0px;}
body
{
transition: 0.3s;
}
@media all and (orientation:landscape)
{
body
{
background: black;
}
div
{
position: absolute;
width: 100px;
height: 100px;
left: 20px;top: 50px;
}
}
@media all and (orientation:portrait)
{
body
{
background: yellow;
}
div
{
position: absolute;width: 50px;height: 150px;
background: green;
left: 50px;top: 20px;
}
}
</style>
</head>
<body>
</body>
</html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
解释:横屏黑色.竖屏(例如手机端)黄色.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="1.css" media="(orientation:landscape)">
<link rel="stylesheet" type="text/css" href="2.css" media="(orientation:portrait)">
<style type="text/css">
*{padding: 0px;margin: 0px;}
</style>
</head>
<body>
<div></div>
</body>
</html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
1.css
body{background:black;}
2.css
body{background:red;}
横屏黑色,竖屏红色.
<!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 type="text/css">
*{margin: 0;padding: 0;}
div{transition:0.9s;}
@media all and (max-width: 600px){
div{width: 200px;height: 200px;background: red};
}
@media all and (min-width: 600px) and (max-width: 800px){
div{width: 300px;height: 300px;background: green};
}
@media all and (min-width: 800px){
div{width: 400px;height: 400px;background: yellow};
}
</style>
</head>
<body>
<div id='div1'></div>
<script type="text/javascript">
div1.οnclick=function()
{
if(innerWidth<600)
{
alert(1);
}
else if(innerWidth>600&&innerWidth<800)
{
alert(2);
}
else
{
alert(3);
}
}
</script>
</body>
</html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
在小于600的情况下,红色。.点击弹出1
在600以上800以下的情况下,green。.点击弹出2
在800以上的话,是黄色.点击弹出3
文章来源: blog.csdn.net,作者:贵哥的编程之路(陈业贵),版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq_37805832/article/details/109324754
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)