Reputation: 1565
I searched and found many examples on web, and even here in stackoverflow, but none of them is 100% explained. For those who wants to place a answer with CSS media screen, please don't do that I know about it. But this question is more for IE7+. since it doesn't support "CSS media screen".
This is the example i found:
$(document).ready(function() {
if (screen.width>=800) {
$("link[rel=stylesheet]:not(:first)").attr({href : "style1.css"});
} else {
$("link[rel=stylesheet]:not(:first)").attr({href : "style.css"});
}
});
I am new to jquery, so how to change this script in case if I have 4 different styles for 4 different screen resolutions.
So I would liek to have something like this:
Please help me!
Upvotes: 2
Views: 7497
Reputation: 14827
You don't need jQuery for this, using CSS3 media queries instead:
@media only screen and (max-width : 600px) {
/* Styles for 1*/
}
@media only screen and (min-width : 601px) and (max-width : 1280px) {
/* Styles for 2 */
}
@media only screen and (min-width : 1281px) and (max-width : 1600px) {
/* Styles for 3 */
}
@media only screen and (min-width : 1601px) {
/* Styles for 4 */
}
Ok, as @RaduChelariu mention, to support older browser like IE7 you can use a custom plugin to make CSS3 media queries compatible with.
Upvotes: 5
Reputation: 446
Actually, media queries are the answer. Just use this shiv to add media query support to IE7 and 8 and you're good to go. No need for messy javascript.
Upvotes: 1