怎样通过css的media属性,适配不同分辨率的终端设备,示比例如以下:

<!DOCTYPE html>
<html>
<head>
<title>首页</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style>
@media (max-width:768px) {
#div1 {
width: 400px;
margin: 0 auto;
background:url('../img/1.JPG');
}
#img2,#img3 {
width: 100px;
}
}
@media (min-width:768px) {
#div1 {
width: 600px;
margin: 0 auto;
background:url('../img/1.JPG');
}
#img2,#img3 {
width: 200px;
}
}
@media (min-width:992px) {
#div1 {
width: 800px;
margin: 0 auto;
background:url('../img/1.JPG');
}
#img2,#img3 {
width: 300px;
}
} @media (min-width:1200px) {
#div1 {
width: 1000px;
margin: 0 auto;
background:url('../img/1.JPG');
}
#img2,#img3 {
width: 400px;
}
}
</style>
</head>
<body>
<div id="div1">
<img id="img2" alt="img2" src="../img/2.JPG">
<img id="img3" alt="img3" src="../img/3.JPG">
</div>
</body>
</html>

当然。也能够依据终端分辨率的变化去引用不同的css文件,示比例如以下:

<!DOCTYPE html>
<html>
<head>
<title>首页</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" media="(max-width: 768px)" href="../css/max-768px.css">
<link rel="stylesheet" media="(min-width: 768px)" href="../css/min-768px.css">
<link rel="stylesheet" media="(min-width: 992px)" href="../css/min-992px.css">
<link rel="stylesheet" media="(min-width: 1200px)" href="../css/min-1200px.css">
</head>
<body>
<div id="div1">
<img id="img2" alt="img2" src="../img/2.JPG">
<img id="img3" alt="img3" src="../img/3.JPG">
</div>
</body>
</html>

注意: 仅仅须要将第一个文件中面的ccs写入四个css文件。

最新文章

  1. 洛谷P3390 【模板】矩阵快速幂
  2. MySQL数据导出与导入
  3. uGUI VS NGUI
  4. linux下格式化硬盘与挂载硬盘
  5. k近邻法的C++实现:kd树
  6. -sh: ./helloworld: not found
  7. 46. Permutations
  8. 设计模式——单例模式 (C++实现)
  9. java基础易错点总结(一)
  10. C/C++堆栈指引(转)
  11. HDU 4721 Food and Productivity (二分+树状数组)
  12. Tcl学习之--语法|变量
  13. java 乱码详解_jsp中pageEncoding、charset=UTF -8&quot;、request.setCharacterEncoding(&quot;UTF-8&quot;)
  14. JAVA Eclipse使用Maven构建web项目详解(SSM框架)
  15. Django框架获取各种form表单数据
  16. SQLGetEnvAttr
  17. innerText 与 innerHtml的区别
  18. ASM - ByteCode插件下载、安装以及相关遇到的问题
  19. Scala_类和对象
  20. KVM管理概述

热门文章

  1. 离线使用nuget
  2. ES6新特性-----变量和字符串
  3. 算法分析-堆排序 HeapSort 优先级队列
  4. ERS卫星
  5. ECO
  6. windows和linux下获取当前程序路径以及cpu数
  7. POJ 1759 Garland(二分答案)
  8. 【Python】iiblogs ——命令行下的网页收藏夹
  9. aix 在线软件包安装 字符集 mysql安装
  10. R语言初涉