1.媒体查询:
@media screen and (min-width: 320px) and (max-width: 480px){
//在这里写小屏幕设备的样式
}
@media only screen and (min-width: 321px) and (max-width: 1024px){
//这里写宽度大于321px小于1024px的样式(一般是平板电脑)
}
@media only screen and (min-width: 1029px){
//这里写pc客户端的样式
}
2.用js根据客户端输出对应样式:
用asp、php后台判断更保险,js在前端,有可能被用户禁止
function loadCSS() {
if((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|wOSBrowser|BrowserNG|WebOS)/i))) {
document.write('<link href="css/pad-phone.css" rel="stylesheet" type="text/css" media="screen" />');
}
else {
document.write('<link href="css/pc.css" rel="stylesheet" type="text/css" media="screen" />');
}
}
loadCSS();
3.只要求判断根据屏幕宽度选择不同的CSS样式表:
<script language=javascript>
<!--
if (screen.width == 800){
document.write('<link rel=stylesheet type="text/css" href="css800.css">')
}else {
document.write('<link rel=stylesheet type="text/css" href="css1024.css">')
}
//-->
</script>