Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS中规则@media的用法 #136

Open
wangbow opened this issue Sep 19, 2016 · 0 comments
Open

CSS中规则@media的用法 #136

wangbow opened this issue Sep 19, 2016 · 0 comments

Comments

@wangbow
Copy link
Contributor

wangbow commented Sep 19, 2016

CSS中@规则是由@符号开始的,例如@import@page等。

@media就是其中的一个规则。
@media可以让你根据不同的屏幕大小而使用不同的样式,这可以使得不需要js代码就能实现响应式布局。
不过@media只能用于较新的浏览器,对于老式的IE,不支持。下面是@media支持的浏览器。
wkiol1s0jyxg0tnmaabm5ac6nug635

@media的语法比较简单,一眼就能看懂。
@media mediatype and|not|only (media feature) {
CSS-Code;
}
可以参考http://www.w3cschool.cc/cssref/css3-pr-mediaquery.html值的说明。
其中mediatype就是媒体类型,可以包括好多种,最常用的就是screen,其他多数已经作废。
media feature就定义了这个media设备的一些特征,简单的说就是媒体满足什么条件,常用的就是max-width,min-width。
通过指定屏幕的大小,而采用不同的样式。
举个例子演示如何用@media规则实现响应式布局。
rq b22 u4p_ np1 8n5a
n7xkq 8b6oku3dn9p2a8g 5
v43e ed j_uv e7_c hp5h

@media only screen and (min- 620px) and (max-width: 930px)
@media only screen and (max- 620px)
上述2个规则,当屏幕宽度在620px以下,和620px-930px,使用的contain样式是不同的。
截图:
当浏览器宽度在1024px的情况下,显示效果如下:
wkiom1s0jlybx2vwaaa5n3vxi00269

当浏览器宽度在680px的情况下,显示如下:
wkiom1s0jlzr8jd9aabl7rduu3w939
当浏览器宽度在480px的情况下,显示如下:
wkiom1s0jlyxshr9aabvphcbc60083

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant