<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Link study</title>
<!--竖版本使用的样式-->
<style media="all and (orientation:portrait)" type="text/css">
#landscape { display: none; }
body {background:red}
</style>
<!--横版本使用的样式-->
<style media="all and (orientation:landscape)" type="text/css">
#portrait { display: none; }
body {background:green}
</style>
</head>
<body>
</body>
</html>
本文介绍了一种使用CSS媒体查询实现网页布局在竖版和横版方向自动切换的方法。通过检测设备的方向来改变网页背景颜色及元素显示状态,适用于需要根据不同设备方向调整布局的场景。
388

被折叠的 条评论
为什么被折叠?



