You can check the actual pixel ratio with -webkit-min-device-pixel-ratio
in media queries. For example, the Galaxy S4 and onwards has a -webkit-device-pixel-ratio
of 4
, whereas the S3 only has a ratio of 3
. Targeting based on this will allow you to present different mobile views per device.
Here's an example that will only target an S3:
@media screen
and (device-width: 320px)
and (device-height: 640px)
and (-webkit-device-pixel-ratio: 2) {
}
You can find a complete list of devices and their relevant media queries on this CSS Tricks page.
Remember to include a META
tag in your <head>
section that allows for scaling:
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
The actual redirection you're talking about can't be handled via CSS, and is typically handled via JavaScript.
This can be (crudely) done simply with a check against window.screen.width
:
if (window.screen.width < 1000) {
window.location = 'm.mysite.com';
}
Though it's much safer to check against the user agent:
var isMobile = function() {
console.log("Navigator: " + navigator.userAgent);
return /(iphone|ipod|ipad|android|blackberry|windows ce|palm|symbian)/i.test(navigator.userAgent);
};
Hope this helps! :)