@media screen and (orientation: portrait){ //竖屏状态下 }
@media screen and (orientation: landscape) { //横屏状态下 }
通过link 实现横竖屏不同的css
<link rel="stylesheet" media="all and (orientation:portrait)" href="portrait.css"> 竖屏
<link rel="stylesheet" media="all and (orientation:landscape)" href="landscape.css"> 横屏
2.js实现强制横屏
(function () {
function resize() {
var body = document.getElementsByTagName('body')[0];
var html = document.getElementsByTagName('html')[0];
var width = html.clientWidth;
var height = html.clientHeight;
var max = width > height ? width : height;
var min = width > height ? height : width;
body.style.width = max + "px";
body.style.height = min + "px";
}
resize();
window.addEventListener("resize", resize)
})();
原文链接:https://blog.csdn.net/u010934423/article/details/78867605