In CSS media the difference between width and device-width can be a bit muddled, so lets expound on that a bit. device-width refers to the width of the device itself, in other words, the screen resolution of the device. Lets say your screen's resolution is 1440 x 900. This means the screen is 1440 pixels across, so it has a device-width of 1440px. Most mobile phones have a device-width of 480px or lower, including the popular iPhone 4 (with device-width: 320px), despite it technically having a 640 x 960 resolution. This is due to iPhone 4's retina display, which crams two device pixels into each CSS pixel on the screen. This is true for the Ipad 3 as well; its reported device-width is 768px just like its predecessors, even though its actual screen resolution is 1536px x 2048px. In general width is more versatile when it comes to creating responsive webpages, though device-width is useful when you wish to specifically target mobile devices (and not desktops with a small browser window for example), as rarely do desktops have screen resolutions below a certain number such as 320px x 480px.

The below shows the screen resolution and CSS media device dimensions of some of the popular devices out there:

CSS Media Dimensions
Device resolution (px) device-width/ device-height (px)
iPhone 320 x 480 320 x 480, in both portrait and landscape mode
iPhone 4 640 x 960 320 x 480, in both portrait and landscape mode. device-pixel-ratio is 2
iPhone 5, 5s 640 x 1136 320 x 568, in both portrait and landscape mode. device-pixel-ratio is 2
iPhone 6 750 x 1334 375 x 667, in both portrait and landscape mode. device-pixel-ratio is 2
iPhone 6 plus 1242 x 2208 414 x 736, in both portrait and landscape mode. device-pixel-ratio is 3
iPad 1 and 2 768 x 1024 768 x 1024, in both portrait and landscape mode
iPad 3 1536 x 2048 768 x 1024, in both portrait and landscape mode

CSS pixel density is 2

Samsung Galaxy S I and II 480 x 800 320 x 533, in portrait mode

CSS pixel density is 1.5

Samsung Galaxy S III 720 x 1280 360? x 640?, in portrait mode
HTC Evo 3D 540 x 960 360 x 640, portrait mode

CSS pixel density is 1.5

Amazon Kindle Fire 1024 x 600 1024 x 600, landscape mode

Just to complicate things even more, in iPhone and iPad devices, the device-width always corresponds to the width of the device in portrait mode, regardless of whether the device is in that mode or landscape instead. With other devices, its device-width changes depending on its orientation.

* For a more complete list of devices and their screen resolutions, visit this page.

Lets see some more CSS media queries now that capture different devices and screen dimensions:

/* #### Mobile Phones Portrait #### */
@media screen and (max-device-width: 480px) and (orientation: portrait){
/* some CSS here */
} /* #### Mobile Phones Landscape #### */
@media screen and (max-device-width: 640px) and (orientation: landscape){
/* some CSS here */
} /* #### Mobile Phones Portrait or Landscape #### */
@media screen and (max-device-width: 640px){
/* some CSS here */
} /* #### iPhone 4+ Portrait or Landscape #### */
@media screen and (min-device-width: 320px) and (-webkit-min-device-pixel-ratio: 2){
/* some CSS here */
} /* #### iPhone 5 Portrait or Landscape #### */
@media (device-height: 568px) and (device-width: 320px) and (-webkit-min-device-pixel-ratio: 2){
/* some CSS here */
} /* #### iPhone 6 and 6 plus Portrait or Landscape #### */
@media (min-device-height: 667px) and (min-device-width: 375px) and (-webkit-min-device-pixel-ratio: 3){
/* some CSS here */
} /* #### Tablets Portrait or Landscape #### */
@media screen and (min-device-width: 768px) and (max-device-width: 1024px){
/* some CSS here */
} /* #### Desktops #### */
@media screen and (min-width: 1024px){
/* some CSS here */
}

转载:http://www.javascriptkit.com/dhtmltutors/cssmediaqueries2.shtml

CSS媒体查询 width VS device-width的更多相关文章

  1. 使用 CSS 媒体查询创建响应式网站

    简介 现今每天都有更多的手机和平板电脑问市.消费者能够拥有可想象到的各种规格和形状的设备,但是网站开发人员却面临一个挑战:如何使他们的网站在传统浏览器.手机和平板电脑浏览器上有很好的效果,如何在各种大 ...

  2. CSS 媒体查询创建响应式网站

    使用 CSS 媒体查询创建响应式网站  适用于所有屏幕大小的设计 固定宽度的静态网站很快被灵活的响应式设计所取代,该设计可以根据屏幕大小进行上扩和下扩.利用响应式设计,无论您采用什么设备或屏幕来访问网 ...

  3. 纯CSS + 媒体查询实现网页导航特效

    纯css+媒体查询实现网页导航特效 附上效果图: 代码如下,复制即可使用: <!DOCTYPE html> <html lang="en"> <hea ...

  4. CSS 媒体查询 响应式

    媒体查询 从 CSS 版本 2 开始,就可以通过媒体类型在 CSS 中获得媒体支持.如果您曾经使用过打印样式表,那么您可能已经使用过媒体类型.清单 1 展示了一个示例. 清单 1. 使用媒体类型 &l ...

  5. css媒体查询aspect-ratio宽高比在less中的使用

    css媒体查询有一个 宽高比很方便,aspect-ratio ,可以直接使用宽/高 来进行页面适配   使用样例如下: // 宽高比在((320/50)+(728/90))/2 两个尺寸中间值以内 适 ...

  6. 我的Vue之旅、04 CSS媒体查询完全指南(Media Quires)

    什么是SCSS Sass: Sass Basics (sass-lang.com) SCSS 是 CSS 的预处理器,它比常规 CSS 更强大. 可以嵌套选择器,更好维护.管理代码. 可以将各种值存储 ...

  7. css媒体查询:响应式网站

    css媒体查询:响应式网站 媒体查询 包含了一个媒体类型和至少一个使用如宽度.高度和颜色等媒体属性来限制样式表范围的表达式.CSS3加入的媒体查询使得无需修改内容便可以使样式应用于某些特定的设备范围. ...

  8. 巧妙使用CSS媒体查询(Media Queries)和JavaScript判断浏览器设备类型的好方法

    有无数的理由要求我们在任何时候都应该知道用户是使用的什么设备浏览我们的网站——宽屏,普通屏,平板,手机?知道这些特征,我们web应用的CSS和JavaScript才能同步做相应的操作.在给Mozill ...

  9. CSS:使用CSS媒体查询创建响应式布局

    现如今在Web前端领域,BootStrap是一个最流行的UI库,其12列的栅栏系统为响应式布局提供了一种对程序员来说很好操作的模式. 追究Bootstrap的内在原理,其实就是通过媒体查询来完成对不同 ...

  10. CSS媒体查询及其使用

    1.什么是媒体查询 媒体查询可以让我们根据设备显示器的特性(如视口宽度.屏幕比例.设备方向:横向或纵向)为其设定CSS样式,媒体查询由媒体类型和一个或多个检测媒体特性的条件表达式组成.媒体查询中可用于 ...

随机推荐

  1. 在GCE上安装Apache、tomcat等

    1.安装Apache2.2.3 (虚机的操作系统是CentOS7) sudo yum install wget -y cd /opt sudo wget http://archive.apache.o ...

  2. BigDecimal类型、Long类型判断值是否相等,以及BigDecimal加减乘除

    //Long是需要比较精度的,所以要用longValueif(project.getFriendId().longValue() != friendId.longValue()) { return t ...

  3. LeetCode:路径总和【112】

    LeetCode:路径总和[112] 题目描述 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和. 说明: 叶子节点是指没有子节点的节点. 示例 ...

  4. Django 之基础续

    1.路由系统之动态路由 前言:还记得之前的分页效果,这个如何实现呢?答案就是动态路由. url(r'^detail/(\d+)/$', views.detail), url(r'^detail2/(\ ...

  5. HackerRank - fibonacci-modified 【大数】

    思路 用PYTHON 或 JAVA 干掉 AC代码 a, b, n = map(int, input().split()) for i in range (2, n, 1) : temp = b b ...

  6. mysql ERROR 1045 (28000): Access denied (using password: YES)

    mysql 安装完成后 mysql -u root -p #让输入密码直接回车就能登录 设置mysql的root用户初始密码: mysqladmin -u root password 'root' 解 ...

  7. MongoDB部署指南

    下載安裝包 http://www.mongodb.org/ 安裝MongoDB systemLog: destination: file path: E:\MongoDB\log\mongo.log ...

  8. post请求和get请求content_type的种类

    get请求的headers中没有content-type这个字段,post 的 content-type 有两种 : application/x-www-form-urlencoded 这种就是一般的 ...

  9. 对matrix,dataframe的操作函数

    1.每行(列)的平均值:rowMeans() ; colMeans() 输入:数值型矩阵:数值型数据框 输出:向量 2.每行(列)的总和:rowSums() ;colSums() 输入:数值型矩阵,数 ...

  10. Docker 配置代理

    最近在k8s上部署helm 老提示无法下载镜像,因为伟大的祖国的长城Firewall....导致k8s根本玩不了..... 第一步:配置系统代理 # vim .bashrc export http_p ...