How can I prompt user to rotate device if in a certain mode landscape or portrait, similar to GameInformer App

后端 未结 2 1691
挽巷
挽巷 2021-02-09 18:02

I have a website that is best viewed in Landscape mode. How can I have it so if the user loads the website in landscape mode it is fine but if it loads in Portrait mode or they

2条回答
  •  悲哀的现实
    2021-02-09 18:58

    Instead of jQuery/JS you can use CSS with a styled div container instead, which is only shown when the device is in portrait mode.

    You can catch the orientation with a media query

    Example:

    /* for all screens */
    #info {display: none;}
    
    /* only when orientation is in portrait mode */
    @media all and (orientation:portrait) {
        #info {
             display: block;
        }
    }
    

提交回复
热议问题