不同分辨率js调用不同css问题

来源:百度知道 编辑:UC知道 时间:2024/05/12 01:03:09
不同分辨率js调用不同css问题:
例如:1024-a.css;800-b.css;1280-c.css;其他-d.css
网站上有一种方法 但是我JS学的很差
function setActiveStyleSheet(title){
document.getElementsByTagName("link")[0].href="style/"+title;
}
里面link和他的元素[0]是代表什么,包括style
最好能按我CSS名全部写给我看看~~~~~新手分不多~~~

根据不同分辨率或不同窗口大小加载不同的css,让网页显示最合适的布局,是网站设计常用到的。
一、根据屏幕分辨率大小加载不同CSS.
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="" rel="stylesheet" type="text/css" id="css" /> <!--备注:这里写一个带ID="css" 的空的link样式-->
<script>
var w=window.screen.width;//先获取屏幕分辨率大小
var c;
if(w==1280){
c="a.css";
}else if(w==1024){
c="d.css";
}else if(w==800){
c="c.css";
}else{
c="d.css";
}
document.getElementById("css").href=c;
</script>
</head>
<body>正文</body>
</html>
二、根据浏览器窗口大小加载不同CSS
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="