如何在屏幕width = 1360px
加载屏幕width = 1600px
和 xyz.css 时加载 abc.css 文件。我怎么能用javascript做到这一点?
答案 0 :(得分:2)
@import url("abc.css") (width: 1360px);
@import url("xyz.css") (width: 1600px);
答案 1 :(得分:0)
您可以在链接标记中指定宽度,即: -
<link rel='stylesheet' media='screen and (min-width: 701px) and (max-width: 900px)' href='css/medium.css' />
此样式表仅在当前浏览器窗口宽度介于701和900像素之间时生效。
答案 2 :(得分:-1)
来自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" />