准备了两套CSS,请问如何在宽屏和窄屏之间切换?
发布网友
发布时间:2022-05-01 02:15
我来回答
共2个回答
热心网友
时间:2022-06-22 08:49
<html>
<head>
<link id="screenCss" href="宽屏的CSS文件.css" media="screen" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var height = window.screen.height;// 获取屏幕高度
var width = window.screen.width; // 获取屏幕宽度
var styleFile = "宽屏的CSS文件.css";
if(width < 1600 && height < 900) {
styleFile = "窄屏的CSS文件.css";
}
document.getElementById("screenCss").href = styleFile;
});
</script>
</head>
<body>
</html>
热心网友
时间:2022-06-22 08:50
有个CSS3方法,不过有点麻烦:
在头部分这么写:
<link rel="stylesheet" media="screen and (max-width: 1599px)" href="x.css" />
<link rel="stylesheet" media="screen and (min-width: 1600px)" href="x1600pxwidth.css" />
<!--[if ie 6]>
<link rel="stylesheet" href="x.css" />
<! [endif]-->