Is there a way to force horizontal / landscape layout on mobile devices?

后端 未结 2 1347
孤城傲影
孤城傲影 2020-12-01 13:20

I\'m building a mobile version of a website, and in this specific case it would look perfect in horizontal layout. Is there a way to force this layout no matter user setting

2条回答
  •  半阙折子戏
    2020-12-01 13:49

    There is a hack that will accomplish this, but I seriously advise against using it - your design should adapt to whether someone is in portrait or landscape mode.

    Step 1: Query the window.orientation property to see if you're in landscape or portrait mode

    Step 2: If you're in portrait mode use a -webkit-transform rotate (-90) on a div that's wrapping your entire page to force it into a landscape layout.

    This won't work quite correctly - the browser UI will still be in portrait mode, but presumably the user will figure out that they're supposed to rotate the phone back into landscape mode in order to view the content. This is incredibly annoying to users - there is probably a good reason they are trying to read your site in portrait mode.

提交回复
热议问题