How to load abc.css file when the screen width = 1360px
and xyz.css load whenthe screen width = 1600px
. How can i do this with javascript?
@import url("abc.css") (width: 1360px);
@import url("xyz.css") (width: 1600px);
@import
supports media queries .
you can simply specify your width in your link tag ie:-
<link rel='stylesheet' media='screen and (min-width: 701px) and (max-width: 900px)' href='css/medium.css' />
this stylesheet will only take affect when the current browser window is between 701 and 900 pixels in width.
From css-tricks
HTML
<link rel="stylesheet" type="text/css" href="main.css" />
<link id="size-stylesheet" rel="stylesheet" type="text/css" href="narrow.css" />
jQuery
function adjustStyle(width) {
width = parseInt(width);
if (width < 701) {
$("#size-stylesheet").attr("href", "css/narrow.css");
} else if ((width >= 701) && (width < 900)) {
$("#size-stylesheet").attr("href", "css/medium.css");
} else {
$("#size-stylesheet").attr("href", "css/wide.css");
}
}
$(function() {
adjustStyle($(this).width());
$(window).resize(function() {
adjustStyle($(this).width());
});
});
HTML
<link rel="stylesheet" media="screen and (min-device-width: 800px)" href="800.css" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.