Background
I have a web application that works both on desktop (rendered inside iframe, fixed width align right), and mobile (full screen). And I'd like to create a CSS rules (within inside the iframe's document) with media queries that applies only to mobile devices, but not desktop.
More Specific Background
Thanks to @Andy that's asking the right questions in the comment.
Our application is sold as two different products. The standalone application (i.e. non-iframe) and the embedded application (i.e. iframe) within our client's website. The two products have two different styling requirements: the standalone application will have global styling across our clients, while the embedded application must match each client's website color schemes
When integrating embedded application on our client's mobile site, we found that they have <meta name="viewport" content="width=320">
that zooms in all elements, we couldn't edit this meta tag. Therefore we'd like to apply a CSS rule only for embedded application, mobile view, and this client only, to fix the enlarged elements.
CSS Media Query max-width
Using the standard max-width query won't work because even on desktop the width recognized is the iframe's width so it's always considered mobile.
@media screen and (max-width:480px) {
... /* this still runs on both mobile and desktop */
}
CSS Media Query max-device-width
Searched and read around the internet and found max-device-width
:
@media screen and (max-device-width:480px) {
... /* this runs on mobile devices only */
}
at first this seem to work as it looks for device's width instead of document's width. However my concerns are:
device-width
query is deprecated https://stackoverflow.com/a/18500871/1019950- On desktop's (i.e. Chrome) mobile emulator,
max-device-width
still considers desktop's screen width, so it doesn't apply the mobile CSS rules.
How to create a media query that works inside iframe and applicable to mobile-devices (or mobile emulator) only, i.e. top document's width is less than 480px?