怎样通过css的media属性,适配不同分辨率的终端设备?
2024-10-15 12:53:36
怎样通过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文件。
最新文章
- 洛谷P3390 【模板】矩阵快速幂
- MySQL数据导出与导入
- uGUI VS NGUI
- linux下格式化硬盘与挂载硬盘
- k近邻法的C++实现:kd树
- -sh: ./helloworld: not found
- 46. Permutations
- 设计模式——单例模式 (C++实现)
- java基础易错点总结(一)
- C/C++堆栈指引(转)
- HDU 4721 Food and Productivity (二分+树状数组)
- Tcl学习之--语法|变量
- java 乱码详解_jsp中pageEncoding、charset=UTF -8";、request.setCharacterEncoding(";UTF-8";)
- JAVA Eclipse使用Maven构建web项目详解(SSM框架)
- Django框架获取各种form表单数据
- SQLGetEnvAttr
- innerText 与 innerHtml的区别
- ASM - ByteCode插件下载、安装以及相关遇到的问题
- Scala_类和对象
- KVM管理概述