①针对800、1280、1440、1600、1920等分辨率,建立不一样的css文件。而后在各类分辨率css文件下,写css样式表。css
针对一个页面,写多css样式表,按照不一样的要求,有些要求适配1280~1920分辨率,各个分辨率之间,只对页面上的元素进行宽高、尺寸、位置等进行调整,总体的框架是类似或者说是相同的。html
一般是先完成一个分辨率下的css样式表。而后在这个基础之上,对其余分辨率进行调整。css3
②加载方式。浏览器
在HTML页面的<head></head>
标签中,插入<script>代码,在不一样的分辨率下,加载不一样的css样式表。框架
注意这里的js必定要写在<head></head>
标签里面,这样在加载页面内容以前,能够提早把css样式表加载出来学习
<script> // 分辨率大于等于1680,大部分为1920的状况下,调用此css if(window.screen.width >= 1680){ document.write('<link rel="stylesheet" href="css/index_1920.css">'); } // 分辨率在1600-1680的状况下,调用此css else if(window.screen.width >= 1600){ document.write('<link rel="stylesheet" href="css/index_1600.css">'); } // 分辨率小于1600的状况下,调用此css else{ document.write('<link rel="stylesheet" href="css/index.css">'); } </script>
媒体查询是CSS3的新特性,绝大多数浏览器均可兼容这一特性。媒体查询的思路也是根据不一样的分辨率,应用不一样的css样式。(原理同样)spa
学习媒体查询学习地址菜鸟教程-CSS3 @media 查询
ssr
两种使用媒体查询的方式:code
1.根据不一样的分辨率,引入不一样的css样式表(同方法一)htm
<!-- 分辨率低于1280,采用test-01.css样式表 --> <link rel="stylesheet" media="screen and (max-device-width:1280px)" href="test-01.css"> <!-- 分辨率高于1400,采用test-02.css样式表 --> <link rel="stylesheet" media="screen and (min-device-width:1440px)" href="test-02.css">
<style media="screen"> /*分辨率低于1280,采用下面的样式*/ @media screen and (max-device-width:1280px){ div{ width: 200px; height: 200px; background-color: green; } } /*分辨率高于1440,采用下面的样式*/ @media screen and (min-device-width: 1440px){ div{ width: 300px; height: 300px; background-color: red; } } </style>