CSS响应式:根据分辨率加载不同CSS的几个方法

如题所述

一般情况下,根据分辨率加载pc端 wap端 pad端三个css文件,示例:

<link rel="stylesheet" type="text/css" href="./css/style.css" media="all">
<link rel="stylesheet" href="./css/phone.css" media="(max-width:620px)">
<link rel="stylesheet" href="./css/pad.css" media="screen and (max-width:1024px) and (min-width:621px)">

只有一个css文件情况下,根据分辨率调整css样式,示例:

@media screen and  (max-width:620px){
.logo{width: 300px;margin-left: -140px;}
}

@media screen and  (max-width:1024px) and (min-width:621px) {
.logo{width: 220px;margin-left: -99px;}
.nav li:nth-of-type(2),.nav li:nth-of-type(3){width: 8%;}
.nav li:nth-of-type(5),.nav li:nth-of-type(6){width: 12%;}
}

温馨提示:答案为网友推荐,仅供参考
相似回答