CSS3 Media Queries 片段

Responsive设计在现代Web设计中可谓是越来越流行,但很同学们并未理解其真正的设计概念,往往把Responsive视为一种自适应布局。当然有很多同学也在尝试动写Responsive的案例,但如何取其断点左右纠结,如何设置哪几个断点?又从何入手?

Responsive中的断点都依赖于CSS3的Media Queries来决断。曾在CSS3 Media Queries模板使用em单位创建CSS3的Media QueriesiPads和iPones的Media Queries有过这方面的介绍。今天特意根据一些Responsive框架整理了一些常见的Media Queries片段,以供大家参考:

CSS3 Media Queries片段

在这里主要分成三类:移动端、PC端以及一些常见的响应式框架的Media Queries片段。

移动端Media Queries片段

iPhone5

@media screen and (device-aspect-ratio: 40/71) {}

或者:

@media screen and (device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2){}

iPhone 5 In Portrait & Landscape

@media only screen

and (min-device-width : 320px)

and (max-device-width : 568px){

// CSS Style

}

iPhone 5 In Landscape

@media only screen

and (min-device-width : 320px)

and (max-device-width : 568px)

and (orientation : landscape){

// CSS Style

}

iPhone 5 In Portrait

@media only screen

and (min-device-width : 320px)

and (max-device-width : 568px)

and (orientation : portrait){

// CSS Style

}

iPone4

@media only screen and (-webkit-min-device-pixel-ratio : 1.5), only screen and (min-device-pixel-ratio : 1.5) {}

iPhone 3G

@media screen and (device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 1){}

iPhone

/*Landscape*/

@media screen and (max-device-width: 480px) {}

/*Portrait*/

@media screen and (max-device-width: 320px) {}

Blackberry Torch

@media screen and (max-device-width: 480px) {}

Samsung S3

@media only screen and (-webkit-device-pixel-ratio: 2) {}

Google Nexus 7

@media screen and (device-width: 600px) and (device-height: 905px) and (-webkit-min-device-pixel-ratio: 1.331) and (-webkit-max-device-pixel-ratio: 1.332) {}

Samsung Galaxy S3

@media only screen and (-webkit-device-pixel-ratio: 2) {}

Samsung Galaxy S2

@media screen and (device-width: 320px) and (device-height: 533px) and (-webkit-device-pixel-ratio: 1.5) {}

Galaxy Tab 10.1

/*Landscape*/

@media (max-device-width: 1280px) and (orientation: landscape) {}

/*Portrait*/

@media (max-device-width: 800px) and (orientation: portrait) {}

iPad In Portrait & Landscape

@media only screen

and (min-device-width : 768px)

and (max-device-width : 1024px){

// CSS Styles

}

iPad In Landscape

@media only screen

and (min-device-width : 768px)

and (max-device-width : 1024px)

and (orientation : landscape){

// CSS Styles

}

iPad In Portrait

@media only screen

and (min-device-width : 768px)

and (max-device-width : 1024px)

and (orientation : portrait){

// CSS Styles

}

Retina iPad In Portrait & Landscape

@media only screen

and (min-device-width : 768px)

and (max-device-width : 1024px)

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

// CSS Styles

}

Retina iPad in landscape

@media only screen

and (min-device-width : 768px)

and (max-device-width : 1024px)

and (orientation : landscape)

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

// CSS Styles

}

Retina iPad in portrait

@media only screen

and (min-device-width : 768px)

and (max-device-width : 1024px)

and (orientation : portrait)

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

// CSS Styles

}

iPad Mini In Portrait & Landscape

@media only screen

and (min-device-width : 768px)

and (max-device-width : 1024px)

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

// CSS Style

}

iPad Mini In Landscape

@media only screen

and (min-device-width : 768px)

and (max-device-width : 1024px)

and (orientation : landscape)

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

// CSS Style

}

iPad Mini In Portrait

@media only screen

and (min-device-width : 768px)

and (max-device-width : 1024px)

and (orientation : portrait)

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

// CSS Style

}

桌面端

320px

@media screen and (max-width: 320px) {}

640px

@media screen and (max-width: 640px) {}

800px

@media screen and (max-width: 800px) {}

1024px

@media screen and (max-width: 1024px) {}

1028px

@media screen and (max-width: 1028px) {}

除了上面的常见Media Queries片段之外,下面的网站还提供了一些其他的片段:

框架Media Queries片段

Boilerplate

/*URL:http://html5boilerplate.com/*/

/* Smartphones (portrait and landscape) ----------- */

@media only screen

and (min-width : 320px)

and (max-width : 480px) {

/* Styles */

}

/* Smartphones (landscape) ----------- */

@media only screen

and (min-width : 321px) {

/* Styles */

}

/* Smartphones (portrait) ----------- */

@media only screen

and (max-width : 320px) {

/* Styles */

}

/* iPads (portrait and landscape) ----------- */

@media only screen

and (min-width : 768px)

and (max-width : 1024px) {

/* Styles */

}

/* iPads (landscape) ----------- */

@media only screen

and (min-width : 768px)

and (max-width : 1024px)

and (orientation : landscape) {

/* Styles */

}

/* iPads (portrait) ----------- */

@media only screen

and (min-width : 768px)

and (max-width : 1024px)

and (orientation : portrait) {

/* Styles */

}

/* Desktops and laptops ----------- */

@media only screen

and (min-width : 1224px) {

/* Styles */

}

/* Large screens ----------- */

@media only screen

and (min-width : 1824px) {

/* Styles */

}

/* iPhone 4 ----------- */

@media

only screen and (-webkit-min-device-pixel-ratio : 1.5),

only screen and (min-device-pixel-ratio : 1.5) {

/* Styles */

}

Bootstrap的Media Queries

/*URL:http://twitter.github.com/bootstrap*/

/* Large desktop */

@media (min-width: 1200px) { ... }

/* Portrait tablet to landscape and desktop */

@media (min-width: 768px) and (max-width: 979px) { ... }

/* Landscape phone to portrait tablet */

@media (max-width: 767px) { ... }

/* Landscape phones and down */

@media (max-width: 480px) { ... }

Foundation的Media Queries

/*URL:http://foundation.zurb.com/*/

/* We use this media query to add styles to any device that supports media queries */

@media only screen { }

/* Used to alter styles for screens at least 768px wide. This is where the grid changes. */

@media only screen and (min-width: 768px) {}

/* Used to alter styles for screens at least 1280px wide. */

@media only screen and (min-width: 1280px) {}

/* Used to alter styles for screens at least 1440px wide. */

@media only screen and (min-width: 1440px) {}

/* Apply styles to screens in landscape orientation */

@media only screen and (orientation: landscape) {}

/* Apply styles to screens in portrait orientation */

@media only screen and (orientation: portrait) {}

Skeleton的Media Queries

/*URL:http://www.getskeleton.com*/

/* Smaller than standard 960 (devices and browsers) */

@media only screen and (max-width: 959px) {}

/* Tablet Portrait size to standard 960 (devices and browsers) */

@media only screen and (min-width: 768px) and (max-width: 959px) {}

/* All Mobile Sizes (devices and browser) */

@media only screen and (max-width: 767px) {}

/* Mobile Landscape Size to Tablet Portrait (devices and browsers) */

@media only screen and (min-width: 480px) and (max-width: 767px) {}

/* Mobile Portrait Size to Mobile Landscape Size (devices and browsers) */

@media only screen and (max-width: 479px) {}

FRAMELESS的Media Queries

/*URL:http://framelessgrid.com/*/

@media screen and (max-width: 16.875em){}

@media screen and (min-width: 32.5em) and (max-width: 37.4375em),

screen and (min-width: 45em) and (max-width: 56.9375em),

screen and (min-width: 77.5em) and (max-width: 102.4375em),

screen and (min-width: 135em){}

@media screen and (min-width: 102.5em) and (max-width: 117.9375em),

screen and (min-width: 150em){}

@media screen and (min-width: 15em){}

@media screen and (min-width: 30em){}

@media screen and (min-width: 37.5em){}

@media screen and (min-width: 57em){}

@media screen and (min-width: 57em) and (max-width: 117.9375em){}

@media screen and (min-width: 118em){}

Susy的Media Queries

/*URL:http://susy.oddbird.net/*/

@media (min-width: 29em) {}

@media (min-width: 30em) and (max-width: 60em) {}

@media (min-width: 119em) {}

@media (min-width: 33.75em) and (max-width: 67.5em) {}

@media (min-width: 33.75em) and (max-width: 67.5em) {}

Less Framework 4

/*URL:http://lessframework.com/*/

@media only screen and (min-width: 768px) and (max-width: 991px) {}

/* Mobile Layout: 320px (20em). */

@media only screen and (max-width: 767px) {}

/*Wide Mobile Layout: 480px (30em)*/

@media only screen and (min-width: 480px) and (max-width: 767px) {}

Golden Grid System的Media Queries

/*URL:http://goldengridsystem.com/*/

/* @media screen and (min-width: 640px) */

@media screen and (min-width: 40em) {}

/* @media screen and (min-width: 720px) */

@media screen and (min-width: 45em) {}

/* @media screen and (min-width: 888px) */

@media screen and (min-width: 55.5em) {}

/* @media screen and (min-width: 984px) */

@media screen and (min-width: 61.5em) {}

/* @media screen and (min-width: 1200px) */

@media screen and (min-width: 75em) {}

/* @media screen and (min-width: 1392px) */

@media screen and (min-width: 87em) {}

/* @media screen and (min-width: 1680px) */

@media screen and (min-width: 105em) {}

/* @media screen and (min-width: 1872px) */

@media screen and (min-width: 117em) {}

/* @media screen and (min-width: 2080px) */

@media screen and (min-width: 130em) {}

Fluid baseline的Media Queries

/*URL:http://fluidbaselinegrid.com/*/

/* MOBILE PORTRAIT */

@media only screen and (min-width: 320px) {}

/* MOBILE LANDSCAPE */

@media only screen and (min-width: 480px) {}

/* SMALL TABLET */

@media only screen and (min-width: 600px) {}

/* TABLET/NETBOOK */

@media only screen and (min-width: 768px) {}

/* LANDSCAPE TABLET/NETBOOK/LAPTOP */

@media only screen and (min-width: 1024px) {}

@media only screen and (min-width: 1280px) {}

/* WIDESCREEN */

/* Increased body size for legibility */

@media only screen and (min-width: 1400px) {}

320andUP

/*URL:http://stuffandnonsense.co.uk/projects/320andup*/

@media only screen and (min-width: 480px) {

/* 480 */

}

@media only screen and (min-width: 600px) {

/* 600 */

}

@media only screen and (min-width: 768px) {

/* 768*/

}

@media only screen and (min-width: 992px) {

/* 992*/

}

@media only screen and (min-width: 1382px) {

/* 1382 */

}

@media only screen and (-webkit-min-device-pixel-ratio: 1.5),

only screen and (min--moz-device-pixel-ratio: 1.5),

only screen and (min-device-pixel-ratio: 1.5) {

/* 2x*/

}

Gridless

/* URL:http://thatcoolguy.github.com/gridless-boilerplate/ */

@media only screen and (min-width: 480px) {

/* Wide mobile (480px+) styles go here */

}

@media only screen and (min-width: 768px) {

/* Tablets/netbooks (768px+) styles go here */

}

@media only screen and (min-width: 1024px) {

/* Desktops (1024px+) styles go here */

}

TotanTHEMES

/*URL:http://titanthemes.com/*/

/* Smaller than standard 960 (devices and browsers) */

@media only screen and (max-width: 959px) {}

/* Tablet Portrait size to standard 960 (devices and browsers) */

@media only screen and (min-width: 768px) and (max-width: 989px) {}

/* All Mobile Sizes (devices and browser) */

@media only screen and (max-width: 767px) {}

/* Mobile Landscape Size to Tablet Portrait (devices and browsers) */

@media only screen and (min-width: 480px) and (max-width: 767px) {}

/* Mobile Portrait Size to Mobile Landscape Size (devices and browsers) */

@media only screen and (max-width: 479px) {}

Responsive Grid System

/*URL:http://responsive.gs/*/

@media (max-width: 480px) {}

@media (min-width: 480px) and (max-width: 768px) {}

@media (min-width: 768px) {}

@media (min-width: 1024px) {}

@media (min-width: 1200px) {}

本文搜集的是Media Queries在各种设备下的代码片段,希望这些片段能帮大家更好的理解Responsive断点的设置。如果大家有更好的方案,希望能在评论中分享。

2014年04月19日更新

基于视窗宽度的媒体查询断点设置

前提设置body的字体为100%。其具有一个简单的计算公式:100% = 16px = 1em = 14pt

/*Viewport = 1920px*/

@media screen and (max-width: 120em){

}

/*Viewport = 1680px*/

@media screen and (max-width: 105em){

}

/*Viewport = 1400px*/

@media screen and (max-width: 87.5em){

}

/*Viewport = 1200px*/

@media screen and (max-width: 75em){

}

/*Viewport = 1024px*/

@media screen and (max-width: 64em){

}

/*Viewport = 960px*/

@media screen and (max-width: 60em){

}

/*Viewport = 800px*/

@media screen and (max-width : 50em){

}

/*Viewport = 768px*/

@media screen and (max-width : 48em){

}

/*Viewport = 600px*/

@media screen and (max-width: 37.5em){

}

/*Viewport = 480px*/

@media screen and (max-width: 30em){

}

/*Viewport = 320px*/

@media screen and (max-width: 20em){

}

/*Viewport = 240px*/

@media screen and (max-width: 15em){

}

/*

High Resolution/Retina Display Media Queries

*/

/*Pixel Density 3*/

@media(-webkit-min-device-pixel-ratio: 3),(min-resolution: 192dpi){

}

/*Pixel Density 2*/

@media(-webkit-min-device-pixel-ratio: 2),(min-resolution: 192dpi){

}

/*Pixel Density 1.5*/

@media(-webkit-min-device-pixel-ratio: 1.5),(min-resolution: 124.8dpi){

}

/*Pixel Density 1.25*/

@media(-webkit-min-device-pixel-ratio: 1.25),(min-resolution: 120dpi){

}

/*

Printed Style Media Queries

*/

/*Print Resolution 300 dpi*/

@media print and (min-resolution: 300dpi){

}

/*Print Resolution 144 dpi*/

@media print and (min-resolution:144dpi){

}

/*Print Resolution 96 dpi*/

@media print and (min-resolution:96dpi){

}

/*Print Resolution 72 dpi*/

@media print and (resolution:72dpi){

}

时间: 2024-10-05 12:49:10

CSS3 Media Queries 片段的相关文章

响应式web设计之CSS3 Media Queries

开始研究响应式web设计,CSS3 Media Queries是入门. Media Queries,其作用就是允许添加表达式用以确定媒体的环境情况,以此来应用不同的样式表.换句话说,其允许我们在不改变内容的情况下,改变页面的布局以精确适应不同的设备. 那么,Media Queries是如何工作的? 两种方式,一种是直接在link中判断设备的尺寸,然后引用不同的css文件: <link rel="stylesheet" type="text/css" href=

[转]响应式web设计之CSS3 Media Queries

开始研究响应式web设计,CSS3 Media Queries是入门. Media Queries,其作用就是允许添加表达式用以确定媒体的环境情况,以此来应用不同的样式表.换句话说,其允许我们在不改变内容的情况下,改变页面的布局以精确适应不同的设备. 那么,Media Queries是如何工作的? 两种方式,一种是直接在link中判断设备的尺寸,然后引用不同的css文件: <link rel="stylesheet" type="text/css" href=

【CSS3 入门教程系列】CSS3 Media Queries 实现响应式设计

在 CSS2 中,你可以为不同的媒介设备(如屏幕.打印机)指定专用的样式表,而现在借助 CSS3 的 Media Queries 特性,可以更为有效的实现这个功能.你可以为媒介类型添加某些条件,检测设备并采用不同的样式表. 例如,你可以把用于大屏幕上显示的样式和用于移动设备的专用样式放在一个样式文档中,这样,在不改变文档内容的情况下,不同的设备可以呈现不同的界面外观.阅读这篇文章学习 CSS3 Media Queries 的基本功能和国外使用 CSS3 的 Media Queries 特性的优秀

CSS3 Media Queries模板

CSS3 Media Queries一般都是使用“max-width”和“min-width” 两个属性来检查各种设备的分辨大小与样式表所设条件是否满足,如果满足就调用相应的样式.打个比方来说,如果你的Web页面在960px的显屏下显示,那 么首先会通过CSS3 Media Queries进行查询,看看有没有设置这个条件样式,如果找到相应的,就会采用对应下的样式,其他的设备是一样的道理.下面具体看看“max- width”和“min-width”模板: 使用max-width @media sc

&lt;转&gt;CSS3 Media Queries 实现响应式设计

在 CSS2 中,你可以为不同的媒介设备(如屏幕.打印机)指定专用的样式表,而现在借助 CSS3 的 Media Queries 特性,可以更为有效的实现这个功能.你可以为媒介类型添加某些条件,检测设备并采用不同的样式表. 例如,你可以把用于大屏幕上显示的样式和用于移动设备的专用样式放在一个样式文档中,这样,在不改变文档内容的情况下,不同的设备可以呈现不同的界面外观.阅读这篇文章学习 CSS3 Media Queries 的基本功能和国外使用 CSS3 的 Media Queries 特性的优秀

IE8及低版本浏览器不支持CSS3 media queries的解决方法

问题:IE8及其以下低版本IE浏览器在缩小窗口时,UI没有按照相应的要求显示窗口缩小时对应的布局:其他浏览器正常. 定位过程: 其实开始拿到问题时是无从下手,不知所以然,根本就没听说还有media这个CSS属性,就更不知道它的功能了.但是对于解决UI问题,有自己的一套思路,就是首先要思考为什么会错误以及为什么没有错误两个方面,然后针对这两个方面的疑问把html或js或css文件简化再简化,修改再修改,查看UI变化,从而缩小问题范围,最后找出问题根源. 如此我就想为什么其他浏览器界面布局没有问题呢

CSS3 Media Queries 实现网页自适应

文章转载自:爱思资源网http://www.aseoe.com/show-10-261-1.html 导语 接下来会展示如何运用 HTML5 和 CSS3 来设计一个自适应网页.当今银屏分辨率从 320px (iPhone) 到 2560px (大屏显示器) 或者更大.人们也不再仅仅用台式机来浏览网页,现在有手机,平板电脑等等.所以现在屏幕分辨率的范围很大,从 320px (iPhone) 到 2560px (大型显示器),甚至更大.用户也不只是使用台式电脑访问web站点了,他使用手机.笔记本电

CSS3 Media Queries 详解

说起CSS3的新特性,就不得不提到 Media Queries .最近 Max Design 更新的一个泛读列表里,赫然就有关于 Media Queries 的文章.同时位列其中的也有前天我刚刚翻译的 IE9, Opacity 和 Alpha . 虽然标题相同,但本文并不是列表上 CSS3 Media Queries 的译文,因为原版有Demo有例子有图片,全文不长而且不难看懂,所以我也就不翻译了.基于自己已经了解到一定程度,所以就打算自己写. CSS2中有已经定义了 Media 的部分,包括类

HTML5实践 -- 使用CSS3 Media Queries实现响应式设计

转载请注明原创地址:http://www.cnblogs.com/softlover/archive/2012/11/21/2781388.html 现在屏幕分辨率的范围很大,从 320px (iPhone) 到 2560px (大型显示器),甚至更大.用户也不只是使用台式电脑访问web站点了,他使用手机.笔记本电脑.平板电脑.所以传统的设置网站宽度为固定值,已经不能满足需要了.web设计需要适应这种新要求,页面布局需要能够根据访问设备的不同分辨率自动进行调整.本教程将会向你介绍,如何使用htm