使用css3的@media,能够实现针对不一样媒体、不一样分辨率的响应式布局。css
方法1:根据不一样分辨率使用不一样css文件html
<link rel="stylesheet" media="mediatype and|not|only (media feature)" href="mystylesheet.css">css3
例如布局
<link rel="stylesheet" media="screen and (max-width: 1024px)" href="middle.css" /> <link rel="stylesheet" media="screen and (max-width: 600px)" href="small.css" />
方法2:同一css文件中,根据不一样分辨率使用不一样样式spa
.first {background-color: white;} .second {background-color: black;} @media screen and (max-width: 800px) { /*当屏幕尺寸小于800px时,应用下面的CSS样式*/ .first {background-color: green;} .second {background-color: skyblue;} } @media screen and (max-width: 480px) { /*当屏幕尺寸小于480px时,应用下面的CSS样式*/ .first {background-color: yellow;} .second {background-color: red;} }
参考:ssr