js控制手机横屏显示

css控制页面横屏显示

/* 当屏幕为竖屏时应用的样式 */
 @media screen and  (orientation:  portrait){
    /*要横屏显示的内容的外层盒子*/
    #box {
        /* 设置基准点为左上角 */
        transform-origin:top left;
        /* 以左上角为基准点,顺时针旋转90度 然后沿Y轴反方向平移100% */
        /* 为什么沿Y轴,因为旋转使坐标轴方向发生了变化 */
        transform: rotate(90deg) translateY(-100%);
        /*设置元素的宽度为 100%父元素的高度 并提高样式优先级 */
        width: 100vh !important;
         /*设置元素的高度为 100%父元素的宽度  并提高样式优先级 */
        height: 100vw !important; 
    }
}
#box{
    width: 100%;
    height: 100%;
    display: flex;
    border: 1px solid rebeccapurple;
}

 

posted @ 2023-03-15 10:07  lijun12138  阅读(745)  评论(0)    收藏  举报