Skip to content

Instantly share code, notes, and snippets.

@visnup
Created May 5, 2012 20:31
Show Gist options
  • Select an option

  • Save visnup/2605440 to your computer and use it in GitHub Desktop.

Select an option

Save visnup/2605440 to your computer and use it in GitHub Desktop.
"lock" orientation of a website for mobile (iPad, iPhone)
/* if portrait mode is detected, rotate the entire site -90 degrees to hint rotating to landscape */
@media (orientation: portrait) {
body {
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
transform: rotate(-90deg);
}
}
@klihelp
Copy link
Copy Markdown

klihelp commented May 1, 2014

How this rotation will affect the page width and height?

@KillerSquid
Copy link
Copy Markdown

brilliantly simple and effective. Probably a much more 'robust' way to do it but for the simple little web-apps I'm building for my son's iPad this is perfect.

Thanks!

@dcbarans
Copy link
Copy Markdown

This needed further work for me. I ended up using the following for a perfect rotation:
(written in SASS)

@include transform-origin(0% 0%);
@include transform( rotate(90deg));
position: absolute;
left: 100%;

@iamcharlesb
Copy link
Copy Markdown

hi, i saw similar solution in stackoverflow too. Just curious to know why do we need give position as absolute.

@nileshm-cuelogic
Copy link
Copy Markdown

This solution is not working for me on iPhone 6+, any hint?. Whereas it works like a magic on android devices..

@mickey9801
Copy link
Copy Markdown

This solution work on iPhone SE

@baconasia
Copy link
Copy Markdown

Thank you!

@metalvegetarianoprogresivo
Copy link
Copy Markdown

Thanks! Works perfectly on iPad with iOS 2017.

@Metajake
Copy link
Copy Markdown

thanks for illuminating the most simple solution !

@mrinamulhaq
Copy link
Copy Markdown

but after img position will no accurate

@georganix
Copy link
Copy Markdown

Doesn't work on Fixed position elements such as navigation

@jeromemalot
Copy link
Copy Markdown

Pretty smart indeed, but doest not work if your CSS uses vh and vw units.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment