0

I want my website layout like this in landscape orientation:

+------------+---------------------+
| Header     |                     |
|            |        Content      |
| Navigation |                     |
+------------+---------------------+

and like this in portrait orientation:

+---------------------+
|        Header       |
+---------------------|
|                     |
|        Content      |
|                     |
+---------------------+
|      Navigation     |
+---------------------+

How can I achieve this?

I am aware of certain experimental CSS3 technologies(@media queries) to manage screen orientation, but they are not widely implemented and therefore of no use to me.

I am also aware of the many similar questions here on SO, but they all deal with targeting different screen sizes and I do not want that. All I want is to reliably detect orientation accross the most common current browsers, independent of screen size, and without JavaScript. That is, a desktop browser window resized to landscape orientation should result in the same rendering as a handheld mobile device in landscape orientation, independent of the actual pixel width.

2 Answers2

2

You should use css media queries. Yes Roko is right in that css media queries are not longer experimental and supported by most browsers. See caniuse to see that support is prevalent.

On how to use, the css media query with orientation, its has already been answered here. Look for the jsfiddle.

body {
    /* some portrait css */
}

@media only screen and  (orientation : landscape) {
    /* some landscape css */
}

For more information on CSS media queries, see the documentation by mozilla.

Community
  • 1
  • 1
maskie
  • 447
  • 4
  • 8
  • Does that code mean that the `@media`-CSS gets ignored by browsers not supporting `@media`-queries, or will they *always* apply it? –  Jan 02 '15 at 08:40
  • Don't forget to add to your answer the use of `-vendor-` prefixes (like: `-ms-`, `-webkit-`...) – Roko C. Buljan Jan 02 '15 at 08:46
  • 2
    the css media query will be ignored if the browser does not support it. To be specific, in your case, IE8 does not support CSS media queries. This stack overflow link discusses alternatives if you really have to support IE8. http://stackoverflow.com/questions/5769493/ie8-support-for-css-media-query – maskie Jan 02 '15 at 08:48
0

You cannot, simple as that. In your question you rule out all technologies that could possibly let you detect window orientation.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390