我们做移动端项目的时候,为了更好的完善用户体会,经常会需要处理好手机横竖屏时候的效果,下面看一下通过代码如何判断手机是否是横竖屏,两种方式:

一、第一种方式:

<style type="text/css">
body,
html {
margin: 0;
height: 100%;
position: relative;
overflow: hidden;
}
#box {
width: 100%;
height: 100%;
font-size: 20px;
position: relative;
}
#div {
width: 100px;
height: 100px;
background: red;
}
#pop {
display: none;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: #000;
color: #fff;
line-height: 200px;
font-size: 30px;
text-align: center;
}
</style>
</head>
<body>
<div >二、第二种方式
<style type="text/css">
body,
html {
margin: 0;
height: 100%;
position: relative;
overflow: hidden;
}
#box {
position: absolute;
left: 50%;
top: 50%;
font-size: 20px;
position: relative;
}
#div {
width: 100px;
height: 100px;
background: red;
}
</style>
</head>
<body>
<div ></script>

分享技术,分享快乐!

相关文章:

  • 2021-07-26
  • 2021-07-18
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-03
  • 2021-11-01
  • 2021-10-30
相关资源
相似解决方案