Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

media query for smartphone (landscape orientation)

I am developing a smartphone friendly version of a website and I am facing a little problem while working with the media query for the smartphone landscape orientation. For the portrait orientation, I am using the following media query and it's working perfectly fine:

@media only screen and (max-width : 320px) { style goes here }

but when i am using this media query for the landscape orientation (taken from css-tricks.com), the styles which I write for the landscape orientation overwrite the styles which I've put in for the desktop version of my website.

@media only screen and (min-width : 321px) { style goes here }

This is only happening when I am inserting styles for the landscape orientation, this doesn't happen when I assign styles for the portrait orientation.

P.S I am doing the testing on an iPhone 4.

like image 455
Fahad Hasan Avatar asked Apr 11 '13 15:04

Fahad Hasan


People also ask

What is orientation landscape in media query?

Media queries can also be used to change layout of a page depending on the orientation of the browser. You can have a set of CSS properties that will only apply when the browser window is wider than its height, a so called "Landscape" orientation.

What is media orientation?

“Media orientation” refers to the attitude of communication professionals towards mass media. It can be used as an indicator of the status of mediatisation within organisations on the individual level of communication professionals (Kohring, Marcinkowski, Lindner, & Karis, 2013.

What is @media only screen?

only screen: The only keyword is used to prevent older browsers that do not support media queries with media features from applying the specified styles. Syntax: @media only screen and (max-width: width)


1 Answers

You need to set a max-width for your landscape orientation, this won't overwrite your desktop styles until the width is lower than 800px:

@media only screen and (min-width : 321px) and (max-width: 800px) { style goes here }

The other possibility is to wrap your desktop styles into another query and copy them below your portrait and landscape styles:

/* PORTRAIT STYLES */
@media only screen and (max-width : 320px) { style goes here }
/* LANDSCAPE STYLES */
@media only screen and (min-width : 321px) { style goes here }
/* DESKTOP STYLES */
@media only screen and (min-width : 800px) { style goes here }

Note that the Landscape styles will be used for the Desktop version. Sometimes this is a welcome behaviour.

like image 171
nirazul Avatar answered Sep 17 '22 01:09

nirazul