css3 media query orientation,CSS3之media query

本文深入讲解了响应式设计中的媒体查询(media queries)语法,并提供了针对不同设备的具体示例,包括iPhone、iPad、Galaxy S系列等热门设备。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

现在响应式设计应该是码农标配了,今天就学习学习响应式的重量级大杀器 -- media query

语法

media_query_list: [, ]*

media_query: [[only | not]? [ and ]*]

| [ and ]*

expression: ( [: ]? )

media_type: all | aural | braille | handheld | print |

projection | screen | tty | tv | embossed

media_feature: width | min-width | max-width

| height | min-height | max-height

| device-width | min-device-width | max-device-width

| device-height | min-device-height | max-device-height

| aspect-ratio | min-aspect-ratio | max-aspect-ratio

| device-aspect-ratio | min-device-aspect-ratio | max-device-aspect-ratio

| color | min-color | max-color

| color-index | min-color-index | max-color-index

| monochrome | min-monochrome | max-monochrome

| resolution | min-resolution | max-resolution

| scan | grid

蛋疼吧,原谅我~

@media meida_type and media_feature, media_type and media_feature

两种加载方式

@media (max-width: 600px) {

.facet_sidebar {

display: none;

}

}

注意:所有的media query css都会加载,只有符合条的会被解析

逻辑操作符

and 同编程语言里的and

not 同编程语言里的not

逗号

当逗号两边的条件有一个为真都为真, 同编程语言里的or

media type

all | aural | braille | handheld | print |

projection | screen | tty | tv | embossed| 3d-glasses

media feature

color

color-index

aspect-ratio

device-aspect-ratio

device-height

device-width

grid

height

monochrome

orientation : landscape | portrait

resolution

scan

width

常见设备media query

iPhones

/* ----------- iPhone 4 and 4S ----------- */

/* Portrait and Landscape */

@media only screen

and (min-device-width: 320px)

and (max-device-width: 480px)

and (-webkit-min-device-pixel-ratio: 2) {

}

/* Portrait */

@media only screen

and (min-device-width: 320px)

and (max-device-width: 480px)

and (-webkit-min-device-pixel-ratio: 2)

and (orientation: portrait) {

}

/* Landscape */

@media only screen

and (min-device-width: 320px)

and (max-device-width: 480px)

and (-webkit-min-device-pixel-ratio: 2)

and (orientation: landscape) {

}

/* ----------- iPhone 5 and 5S ----------- */

/* Portrait and Landscape */

@media only screen

and (min-device-width: 320px)

and (max-device-width: 568px)

and (-webkit-min-device-pixel-ratio: 2) {

}

/* Portrait */

@media only screen

and (min-device-width: 320px)

and (max-device-width: 568px)

and (-webkit-min-device-pixel-ratio: 2)

and (orientation: portrait) {

}

/* Landscape */

@media only screen

and (min-device-width: 320px)

and (max-device-width: 568px)

and (-webkit-min-device-pixel-ratio: 2)

and (orientation: landscape) {

}

/* ----------- iPhone 6 ----------- */

/* Portrait and Landscape */

@media only screen

and (min-device-width: 375px)

and (max-device-width: 667px)

and (-webkit-min-device-pixel-ratio: 2) {

}

/* Portrait */

@media only screen

and (min-device-width: 375px)

and (max-device-width: 667px)

and (-webkit-min-device-pixel-ratio: 2)

and (orientation: portrait) {

}

/* Landscape */

@media only screen

and (min-device-width: 375px)

and (max-device-width: 667px)

and (-webkit-min-device-pixel-ratio: 2)

and (orientation: landscape) {

}

/* ----------- iPhone 6+ ----------- */

/* Portrait and Landscape */

@media only screen

and (min-device-width: 414px)

and (max-device-width: 736px)

and (-webkit-min-device-pixel-ratio: 3) {

}

/* Portrait */

@media only screen

and (min-device-width: 414px)

and (max-device-width: 736px)

and (-webkit-min-device-pixel-ratio: 3)

and (orientation: portrait) {

}

/* Landscape */

@media only screen

and (min-device-width: 414px)

and (max-device-width: 736px)

and (-webkit-min-device-pixel-ratio: 3)

and (orientation: landscape) {

}

galaxy

/* ----------- Galaxy S3 ----------- */

/* Portrait and Landscape */

@media screen

and (device-width: 320px)

and (device-height: 640px)

and (-webkit-device-pixel-ratio: 2) {

}

/* Portrait */

@media screen

and (device-width: 320px)

and (device-height: 640px)

and (-webkit-device-pixel-ratio: 2)

and (orientation: portrait) {

}

/* Landscape */

@media screen

and (device-width: 320px)

and (device-height: 640px)

and (-webkit-device-pixel-ratio: 2)

and (orientation: landscape) {

}

/* ----------- Galaxy S4 ----------- */

/* Portrait and Landscape */

@media screen

and (device-width: 320px)

and (device-height: 640px)

and (-webkit-device-pixel-ratio: 3) {

}

/* Portrait */

@media screen

and (device-width: 320px)

and (device-height: 640px)

and (-webkit-device-pixel-ratio: 3)

and (orientation: portrait) {

}

/* Landscape */

@media screen

and (device-width: 320px)

and (device-height: 640px)

and (-webkit-device-pixel-ratio: 3)

and (orientation: landscape) {

}

/* ----------- Galaxy S5 ----------- */

/* Portrait and Landscape */

@media screen

and (device-width: 360px)

and (device-height: 640px)

and (-webkit-device-pixel-ratio: 3) {

}

/* Portrait */

@media screen

and (device-width: 360px)

and (device-height: 640px)

and (-webkit-device-pixel-ratio: 3)

and (orientation: portrait) {

}

/* Landscape */

@media screen

and (device-width: 360px)

and (device-height: 640px)

and (-webkit-device-pixel-ratio: 3)

and (orientation: landscape) {

}

htc

/* ----------- HTC One ----------- */

/* Portrait and Landscape */

@media screen

and (device-width: 360px)

and (device-height: 640px)

and (-webkit-device-pixel-ratio: 3) {

}

/* Portrait */

@media screen

and (device-width: 360px)

and (device-height: 640px)

and (-webkit-device-pixel-ratio: 3)

and (orientation: portrait) {

}

/* Landscape */

@media screen

and (device-width: 360px)

and (device-height: 640px)

and (-webkit-device-pixel-ratio: 3)

and (orientation: landscape) {

}

ipad

/* ----------- iPad mini ----------- */

/* Portrait and Landscape */

@media only screen

and (min-device-width: 768px)

and (max-device-width: 1024px)

and (-webkit-min-device-pixel-ratio: 1) {

}

/* Portrait */

@media only screen

and (min-device-width: 768px)

and (max-device-width: 1024px)

and (orientation: portrait)

and (-webkit-min-device-pixel-ratio: 1) {

}

/* Landscape */

@media only screen

and (min-device-width: 768px)

and (max-device-width: 1024px)

and (orientation: landscape)

and (-webkit-min-device-pixel-ratio: 1) {

}

/* ----------- iPad 1 and 2 ----------- */

/* Portrait and Landscape */

@media only screen

and (min-device-width: 768px)

and (max-device-width: 1024px)

and (-webkit-min-device-pixel-ratio: 1) {

}

/* Portrait */

@media only screen

and (min-device-width: 768px)

and (max-device-width: 1024px)

and (orientation: portrait)

and (-webkit-min-device-pixel-ratio: 1) {

}

/* Landscape */

@media only screen

and (min-device-width: 768px)

and (max-device-width: 1024px)

and (orientation: landscape)

and (-webkit-min-device-pixel-ratio: 1) {

}

/* ----------- iPad 3 and 4 ----------- */

/* Portrait and Landscape */

@media only screen

and (min-device-width: 768px)

and (max-device-width: 1024px)

and (-webkit-min-device-pixel-ratio: 2) {

}

/* Portrait */

@media only screen

and (min-device-width: 768px)

and (max-device-width: 1024px)

and (orientation: portrait)

and (-webkit-min-device-pixel-ratio: 2) {

}

/* Landscape */

@media only screen

and (min-device-width: 768px)

and (max-device-width: 1024px)

and (orientation: landscape)

and (-webkit-min-device-pixel-ratio: 2) {

}

nexus 平板

/* ----------- Asus Nexus 7 ----------- */

/* Portrait and Landscape */

@media screen

and (device-width: 601px)

and (device-height: 906px)

and (-webkit-min-device-pixel-ratio: 1.331)

and (-webkit-max-device-pixel-ratio: 1.332) {

}

/* Portrait */

@media screen

and (device-width: 601px)

and (device-height: 906px)

and (-webkit-min-device-pixel-ratio: 1.331)

and (-webkit-max-device-pixel-ratio: 1.332)

and (orientation: portrait) {

}

/* Landscape */

@media screen

and (device-width: 601px)

and (device-height: 906px)

and (-webkit-min-device-pixel-ratio: 1.331)

and (-webkit-max-device-pixel-ratio: 1.332)

and (orientation: landscape) {

}

kindle fire

/* ----------- Kindle Fire HD 7" ----------- */

/* Portrait and Landscape */

@media only screen

and (min-device-width: 800px)

and (max-device-width: 1280px)

and (-webkit-min-device-pixel-ratio: 1.5) {

}

/* Portrait */

@media only screen

and (min-device-width: 800px)

and (max-device-width: 1280px)

and (-webkit-min-device-pixel-ratio: 1.5)

and (orientation: portrait) {

}

/* Landscape */

@media only screen

and (min-device-width: 800px)

and (max-device-width: 1280px)

and (-webkit-min-device-pixel-ratio: 1.5)

and (orientation: landscape) {

}

/* ----------- Kindle Fire HD 8.9" ----------- */

/* Portrait and Landscape */

@media only screen

and (min-device-width: 1200px)

and (max-device-width: 1600px)

and (-webkit-min-device-pixel-ratio: 1.5) {

}

/* Portrait */

@media only screen

and (min-device-width: 1200px)

and (max-device-width: 1600px)

and (-webkit-min-device-pixel-ratio: 1.5)

and (orientation: portrait) {

}

/* Landscape */

@media only screen

and (min-device-width: 1200px)

and (max-device-width: 1600px)

and (-webkit-min-device-pixel-ratio: 1.5)

and (orientation: landscape) {

}

桌面显示器

/* ----------- Non-Retina Screens ----------- */

@media screen

and (min-device-width: 1200px)

and (max-device-width: 1600px)

and (-webkit-min-device-pixel-ratio: 1) {

}

/* ----------- Retina Screens ----------- */

@media screen

and (min-device-width: 1200px)

and (max-device-width: 1600px)

and (-webkit-min-device-pixel-ratio: 2)

and (min-resolution: 192dpi) {

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值