I currently have the following in my HTML document.
<link REL=StyleSheet HREF="/stylesheets/home.css" TYPE="text/css" MEDIA=screen>
<link REL=StyleSheet HREF="/stylesheets/homedark.css" TYPE="text/css" MEDIA=handheld>
However, nothing changes on a handheld device (my Android phone). Is there something I'm doing wrong, or is it just not this simple?
You will need to use more advanced media queries, such as those that target screen size
So something more like
<link rel="stylesheet" href="/stylesheets/homedark.css" type="text/css"
media="screen and (max-device-width: 480px)">
Inside your stylesheet, it would be something like this
@media only screen and (max-device-width: 480px) {
//Your styles here
}
http://www.w3.org/TR/css3-mediaqueries/
Simple JS device detection might be helpful:
if( navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPod/i)){
// link to stylesheet
}
An even better thing to do is use some sort of combo... media queries & device / feature detection.
This is a good overview: http://www.csskarma.com/presentations/cssla/slides/mobile_media_touch.pdf (WARNING: pdf file)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With