本文共 4817 字,大约阅读时间需要 16 分钟。
(PS:原文写于2012年,本文参照原文作了适当修改,不当之处请指出)
现在Web朝着响应式的趋势发展,媒体查询在创建响应式网站中起到了主要作用。
没有媒体查询几乎不能实现响应式设计,利用媒体查询,我们可以针对特定的设备,如显示器、智能手机和平板,写CSS。
媒体查询是响应式设计的核心
在这篇文章中我将分享一些到目前为止我收集到的常用媒体查询。在一些示例中,我可能是错误的,但是不用担心,因为我针对这个开通了评论功能。我把它们分为显示器媒体查询、智能手机媒体查询和平板媒体查询
显示器媒体查询是以屏幕大小为基础划分的
@media screen and (max-width: 640px) { }
@media screen and (max-width: 800px) { }
@media screen and (max-width: 1024px) { }
适用于大部分主流智能手机
/*Landscape Mode*/@media screen and (max-device-width: 480px) { }/* Portrait Mode */@media screen and (max-device-width: 320px) { }
@media only screen and (-webkit-min-device-pixel-ratio : 1.5), only screen and (min-device-pixel-ratio : 1.5) { }
@media only screen and (min-device-width : 320px) and (max-device-width : 568px) { /* 样式写在这里 */}
@media only screen and (min-device-width: 375px) and (max-device-width: 667px) and (orientation : portrait) { /*iPhone 6 Portrait*/}@media only screen and (min-device-width: 375px) and (max-device-width: 667px) and (orientation : landscape) { /*iPhone 6 landscape*/}@media only screen and (min-device-width: 414px) and (max-device-width: 736px) and (orientation : portrait) { /*iPhone 6+ Portrait*/}@media only screen and (min-device-width: 414px) and (max-device-width: 736px) and (orientation : landscape) { /*iPhone 6+ landscape*/}@media only screen and (max-device-width: 640px), only screen and (max-device-width: 667px), only screen and (max-width: 480px){ /*iPhone 6 and iPhone 6+ portrait and landscape*/}@media only screen and (max-device-width: 640px), only screen and (max-device-width: 667px), only screen and (max-width: 480px) and (orientation : portrait){ /*iPhone 6 and iPhone 6+ portrait*/}@media only screen and (max-device-width: 640px), only screen and (max-device-width: 667px), only screen and (max-width: 480px) and (orientation : landscape){ /*iPhone 6 and iPhone 6+ landscape*/}
@media screen and (max-device-width: 480px) { }
这个列表会有点长
/* Landscape Mode */@media (max-device-width: 1024px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 768px) and (orientation: portrait) { }
/* Landscape Mode */@media (max-device-width: 1024px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 768px) and (orientation: portrait) { }
/* Landscape Mode */@media (max-device-width: 1024px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 768px) and (orientation: portrait) { }
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px)and (-webkit-min-device-pixel-ratio: 1) { /* 样式写在这里 */}
/* Landscape Mode */@media (max-device-width: 1280px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 800px) and (orientation: portrait) { }
/* Landscape Mode */@media (max-device-width: 1280px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 800px) and (orientation: portrait) { }
/* Landscape Mode */@media (max-device-width: 1024px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 600px) and (orientation: portrait) { }
/* Landscape Mode */@media (max-device-width: 1024px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 600px) and (orientation: portrait) { }
/* Landscape Mode */@media (max-device-width: 1024px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 768px) and (orientation: portrait) { }
/* Landscape Mode */@media (max-device-width: 1280px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 800px) and (orientation: portrait) { }
/* Landscape Mode */@media (max-device-width: 1280px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 800px) and (orientation: portrait) { }
/* Landscape Mode */@media (max-device-width: 1280px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 768px) and (orientation: portrait) { }
/* Landscape Mode */@media (max-device-width: 1024px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 600px) and (orientation: portrait) { }
/* Landscape Mode */@media (max-device-width: 800px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 480px) and (orientation: portrait) { }
/* Landscape Mode */@media (max-device-width: 1080px) and (orientation: landscape) { }/* Portrait Mode */@media (max-device-width: 800px) and (orientation: portrait) { }
英文原文:
译文出处:
参考文章:
转载地址:http://vytgi.baihongyu.com/