desideratum

  • Archive
  • RSS

iPad Orientation CSS (Revised)

It doesn’t take much foresight to anticipate that with the rise of Natural User Interfaces (NUIs) like the iPhone and iPad, UI designers will have a greater responsibility to optimize for orientation-based contexts. As such, it’s quite prescient that today, the folks at Cloud Four demonstrated how to serve up stylesheets based on device orientation.

Since I have a feeling I’ll be using this quite a bit in the future, I wanted to build on Cloud Four’s work and find a way to alleviate the following issues:

  1. Extra HTTP requests
  2. Not iPad-specific
  3. Lack of reusability

So, without further ado, here’s my proposed revision to the iPad orientation CSS:

<!-- css -->
@media only screen and (max-device-width: 1024px) and (orientation:portrait) { 
    .landscape { display: none; }
}
@media only screen and (max-device-width: 1024px) and (orientation:landscape) { 
    .portrait { display: none; }
}

<!-- example markup -->
<h1 class="portrait">Your device orientation is "portrait"<h1>
<h1 class="landscape">Your device orientation is "landscape"<h1>


As you can see, I’ve also changed the markup in a predictable way. An explanation of the changes and the reasoning behind them can be found below.


1. Extra HTTP requests

Depending on how much work you put into crafting and taking advantage of orientation-based display, you could have entirely different layouts contained in landscape.css and portrait.css. Since extra HTTP requests can bog down page-load time, it would be better performing to embed the media queries into a single stylesheet, if not your main stylesheet as follows:

@media (orientation:portrait) { }
@media (orientation:landscape) { }

The orientation-specific code could then be inserted in between the curly braces. Note that I’ve also removed the “all and” at the beginning of the media query — this is acceptable shorthand per the W3C spec. For more information on CSS3 media queries, please reference the W3C Candidate Recommendation.


2. Not iPad-specific

This CSS targets devices based on their orientation, or (as the W3C explains) based on whether the height of the device is greater or less than the width of the device. What if you only want to target the iPhone and/or iPad and not browsers though? I’m not advocating making Apple devices the new Internet Explorers, but there’s some value in having greater control of your presentation, should you need it.

I posted recently on how to serve up iPad-specific CSS using media queries. To do so, you would change your media queries to target only devices with the “screen” media type that have the maximum device width of the iPad:

@media only screen and (max-device-width: 1024px) and (orientation:portrait) { }

@media only screen and (max-device-width: 1024px) and (orientation:landscape) { }


By extension, if you wanted to serve up iPhone and iPad-specific CSS, you would change your media queries to the following:

@media only screen and (max-device-width: 1024px) and (orientation:portrait), only screen and (max-device-width: 480px) and (orientation:portrait)  { }

@media only screen and (max-device-width: 1024px) and (orientation:landscape), only screen and (max-device-width: 480px) and (orientation:landscape)  { }


3. Lack of reusability

Using classes instead of ID’s to denote orientation-based styles would make it a little easier to manage the logic.

<h1 class="portrait">You're Viewing in Portrait Mode<h1>
<h1 class="landscape">You're Viewing in Landscape Mode<h1>

I’m sure Cloud Four didn’t intend to establish ID’s as a convention for this functionality in their example, but I think considering reusability here is important. How can we make sure the “portrait”/”landscape” semantics are all that’s required to potentially display completely different layouts? Just apply the appropriate classes to whichever elements you want to target with a specific orientation.

Having to duplicate code is cringe-worthy, but understandably necessary if we need to replace content and don’t want to use Javascript. What if, however, instead of replacing content, we want to repurpose the existing content? For example, we might want to change the width of an element based on orientation without replacing it wholesale. In this situation, I don’t believe using classes to abstract the logic is appropriate; all of the styling should be directly targeting the elements from the orientation conditional CSS:

<!-- css -->
#content { width: 960px; }
@media only screen and (max-device-width: 1024px) and (orientation:portrait) {   
    #content { width: 720px; } 
}

<!-- markup -->
<div id="content"></div>


Conclusion

The mechanics of optimizing presentation should be fairly invisible to the user. If possible, we should be able to do nothing but tweak static parts of fluid layouts to better accommodate different device widths; however, that doesn’t mean we should overlook opportunities to better optimize content for the user. And while the iPad might not be the spawn of unicorn and wizard, it’s certainly different.

It’s a mobile device that has the potential to be used as often and in as many contexts as a smartphone, but introduces a whole host of additional accessibility scenarios to worry about.

It has a screen size we’re accustomed to designing for, but that’s not an excuse to stop supporting non-iPhone mobile users.

It supports web standards.

Its interface presents us with novel ways of delighting users, but might lead us to fail less-privileged users whom we’re not as interested in designing for.

More than ever, we are accountable to our users as vanguards of usability, accessibility and progressive enhancement. So let’s keep moving forward, and let’s keep providing best-in-class interfaces for everyone, everywhere.

    • #css
    • #ipad
    • #orientation
    • #web design
    • #mobile design
  • 1 year ago
  • 343
  • Permalink
  • Share
    Tweet

343 Notes/ Hide

  1. seo----service reblogged this from catharsis
  2. penis--enlargement reblogged this from catharsis
  3. handjobsfuckebony liked this
  4. xn----slbefavdc9aecr2ax8cfbiip9g reblogged this from catharsis
  5. xn----slbefaduec3bfcs8cycfbfdiq reblogged this from catharsis
  6. xn----slbefaduec3bfcs8cycfbfdiq reblogged this from catharsis
  7. xn----ylbandbmrbccr2ax8cfbiip9g reblogged this from catharsis
  8. istoselidon0i reblogged this from catharsis
  9. istoselidon1j reblogged this from catharsis
  10. istoselidon7z reblogged this from catharsis
  11. istoselidon1a reblogged this from catharsis
  12. istoselidon2f reblogged this from catharsis
  13. trampolinereviews7l reblogged this from catharsis
  14. istoselidon0v reblogged this from catharsis
  15. istoselidon0i reblogged this from catharsis
  16. istoselidon0v reblogged this from catharsis
  17. istoselidon1a reblogged this from catharsis
  18. xn----ylbandbmrbccr2ax8cfbiip9g reblogged this from catharsis
  19. istoselidon0i reblogged this from catharsis
  20. istoselidon0v reblogged this from catharsis
  21. istoselidon7z reblogged this from catharsis
  22. istoselidon3v reblogged this from catharsis
  23. istoselidon2g reblogged this from catharsis
  24. xn----slbefaduec3bfcs8cycfbfdiq reblogged this from catharsis
  25. xn----slbefavdc9aecr2ax8cfbiip9g reblogged this from catharsis
  26. istoselidon0v reblogged this from catharsis
  27. istoselidon0i reblogged this from catharsis
  28. istoselidon4c reblogged this from catharsis
  29. istoselidon3v reblogged this from catharsis
  30. istoselidon0i reblogged this from catharsis
  31. istoselidon2g reblogged this from catharsis
  32. istoselidon4c reblogged this from catharsis
  33. istoselidon4u reblogged this from catharsis
  34. istoselidon3c reblogged this from catharsis
  35. xn----ylbandbmrbccr2ax8cfbiip9g reblogged this from catharsis
  36. istoselidon4u reblogged this from catharsis
  37. xn----ylbandbmrbccr2ax8cfbiip9g reblogged this from catharsis
  38. forexe-book reblogged this from catharsis
  39. xn----ylbaboebotbdcs8cycfbfdiq reblogged this from catharsis
  40. friedaseowl68 reblogged this from catharsis
  41. lewesde reblogged this from catharsis
  42. pneu-pas-cher-fr reblogged this from catharsis
  43. mutuelle-en-france reblogged this from catharsis
  44. karinadyslin094 reblogged this from catharsis
  45. service-ac liked this
  46. algebracalculator47650 reblogged this from catharsis
  47. servicechiller reblogged this from catharsis
  48. branding-agency-toronto reblogged this from catharsis
  49. brazzers-passwords reblogged this from catharsis
  50. xmyfuckingmurderx reblogged this from catharsis
  51. Show more notesLoading...
← Previous • Next →

Portrait/Logo

These are the thoughts and discoveries of Keith Chu, a web design engineer and culture hacker at Autodesk in San Francisco.

Feel free to check out my work and find out a little bit about me on Foodspotting and Google Reader.

Elsewhere

  • @Catharsis on Twitter
  • Facebook Profile
  • keith on Pinboard
  • keithchurch on Last.fm
  • Linkedin Profile
  • Xbox Live Profile

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr