媒体查询 响应式开发 发表于 2016-09-10 | 分类于 mobile 媒体查询:响应式开发 第一种不同终端的宽度自适应代码: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style> .container { width: 1200px; height: 1000px; margin: 0 auto; background-color: red; } @media screen and (min-width:1200px){ body{ /*当屏幕大小最小满足1200px即大于1200px的时候 */ /*background-color: pink;*/ } .container { width: 1170px; background-color: pink; } } @media screen and (min-width:992px) and (max-width: 1200px){ .container { width: 970px; background: green; } } @media screen and (min-width: 768px) and (max-width: 992px){ .container { width: 750px; background-color: blue; } } @media screen and (max-width: 768px){ .container { width: 100%; background-color: orange; } } </style></head><body><div class="container"></div></body></html> 第二种不同终端宽度自适应代码 :代码覆盖 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style> html,body { margin: 0 ; padding: 0; } .container { width: 1200px; height: 1000px; margin: 0 auto; background-color: red; } /*以覆盖的方式存在*/ @media (max-width: 768px){ .container { width: 100%; background-color: orange; } } @media (min-width: 768px) { .container { width: 750px; background-color: blue; } } @media (min-width:992px) { .container { width: 970px; background: green; } } @media (min-width:1200px){ /*当屏幕大小最小满足1200px即大于1200px的时候 */ /*background-color: pink;*/ .container { width: 1170px; background-color: pink; } } </style></head><body><div class="container"></div></body></html>