Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to disable @media queries or force a resolution? Reason: Allow an iphone to see the desktop site?

Tags:

I have my site HEAVILY modified via @media queries to display very slimdown'd on mobile phones. However, my users are asking for the desktop version of the site (available via a link).

To go a step further, the desktop site itself also gets modified by @media queries depending on resolution. I was thinking of picking one 'desktop' resolution, say 1440x900 and forcing the mobile phone to display at that resolution?

Is this possible, maybe through JavaScript? Alternatively, can these @media queries be disabled altogether?

Thanks!

like image 626
Mark Avatar asked Mar 13 '13 15:03

Mark


People also ask

What is @media screen used for?

The @media CSS at-rule can be used to apply part of a style sheet based on the result of one or more media queries. With it, you specify a media query and a block of CSS to apply to the document if and only if the media query matches the device on which the content is being used.

Is it important to override media queries?

Media queries and @media rules do not affect the behavior of ! important in any way, because they do not have any effect on any part of the cascade. (By extension, this also means you cannot use a @media at-rule to "remove" an ! important flag, even if you use a more specific selector.)

What is the difference between @media and @media screen?

@media is the actually media query. The word screen is adding the 'conditions' to the media query. So @media screen is telling the media query to apply (whatever other conditions) to screens. For example, @media screen and (max-width: 360px) will target only screens with a max-width of 360px.

How do you override a media query?

To override a specific media query rule, append a new css rule after the one you want to override. For example, if the last css rule does not have a media query attached, it will override all previously declared media queries (presuming the same selectors).


2 Answers

I had the same issue with a client. But the problem was there were 120+ CSS files contained the media queries. So what I did is, set the viewport width. I have used this snippet on that site and working fine. Using this, even you can give the option for the users to toggle between responsive design and non-responsive design.

$(document).ready(function(){
   $('meta[name="viewport"]').prop('content', 'width=1440');
});

Note: 1440 is your preferred screen width.

Hope this helps :)

like image 56
Ijas Ameenudeen Avatar answered Sep 20 '22 08:09

Ijas Ameenudeen


I would add a class to your <html> or <body> such as class="force-desktop" and then on your media selector add

@media () {
    body:not(.force-desktop) {
        //styles
    }
}

or something similar

like image 32
romo Avatar answered Sep 18 '22 08:09

romo