我一直在研究媒体查询,我仍然不太了解如何定位某些尺寸的设备。 css
我但愿可以定位台式机,平板电脑和移动设备。 我知道会有一些差别,可是有一个可用于定位这些设备的通用系统会很不错。 web
我找到的一些例子: 浏览器
# Mobile only screen and (min-width: 480px) # Tablet only screen and (min-width: 768px) # Desktop only screen and (min-width: 992px) # Huge only screen and (min-width: 1280px)
要么: ide
# Phone only screen and (max-width:320px) # Tablet only screen and (min-width:321px) and (max-width:768px) # Desktop only screen and (min-width:769px)
您认为这些“断点”对于每一个设备应该是什么? 工具
我使用这个网站来查找分辨率并根据实际数字开发CSS。 个人数字与上述答案有很大不一样,只是个人CSS实际上击中了所需的设备。 布局
此外,在媒体查询后当即调试此代码,例如: 字体
@media only screen and (min-width: 769px) and (max-width: 1281px) { /* for 10 inches tablet screens */ body::before { content: "tablet to some desktop media query (769 > 1281) fired"; font-weight: bold; display: block; text-align: center; background: rgba(255, 255, 0, 0.9); /* Semi-transparent yellow */ position: absolute; top: 0; left: 0; right: 0; z-index: 99; } }
在每一个媒体查询中添加此调试项,您将看到正在应用的查询。 flex
通常的智慧 不是针对特定的设备或尺寸 ,而是从新定义术语“断点”: 网站
您可使用responsivepx.com查找“天然”断点,如Marc Drummond的“断点已死” 。 ui
而后,“断点”成为您的移动设计开始“破坏”的实际点,即中止可用或视觉上使人愉悦。 一旦您拥有一个良好的工做移动网站,没有媒体查询,您能够再也不关注特定大小,只需添加处理连续更大视口的媒体查询。
若是您没有尝试将设计固定到精确的屏幕尺寸,则此方法能够消除针对特定设备的需求 。 每一个断点处的设计自己的完整性确保它能够保持任何尺寸。 换句话说,若是菜单/内容部分/任何中止在某个大小上可用,则设计该大小的断点 , 而不是特定设备大小。
请参阅Lyza Gardner关于行为断点的帖子,以及Zeldman关于Ethan Marcotte的帖子以及响应式网页设计如何从初始想法演变而来 。
此外,具备nav
, header
, main
, section
, footer
等的DOM结构更简单,更具语义性 (避免像div class="header"
具备嵌套内部div
标签的可憎行为),设计响应性更容易,特别是避免浮动经过使用CSS网格布局 (Sarah Drasner的网格生成器是一个很好的工具)和flexbox根据您的RWD设计计划进行安排和从新排序。
这不是像素计数的问题,而是屏幕上字符的实际大小(以毫米或英寸为单位),这取决于像素密度。 所以,“min-width:”和“max-width:”是无用的。 这个问题的完整解释以下: 设备像素比到底是什么?
“@media”查询会考虑像素数和设备像素比,从而产生“虚拟分辨率”,这是您在设计页面时必须考虑的因素:若是您的字体是10px固定宽度而且“虚拟水平分辨率“为300像素,填充一条线须要30个字符。
/* Smartphones (portrait and landscape) ----------- */ @media only screen and (min-device-width : 320px) and (max-device-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-device-width : 768px) and (max-device-width : 1024px) { /* Styles */ } /* iPads (landscape) ----------- */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) { /* Styles */ } /* iPads (portrait) ----------- */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) { /* Styles */ } /********** iPad 3 **********/ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) { /* Styles */ } @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) { /* 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 (min-device-width : 320px) and (max-device-width : 480px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) { /* Styles */ } @media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) { /* Styles */ } /* iPhone 5 ----------- */ @media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){ /* Styles */ } @media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){ /* Styles */ } /* iPhone 6 ----------- */ @media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){ /* Styles */ } @media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){ /* Styles */ } /* iPhone 6+ ----------- */ @media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){ /* Styles */ } @media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){ /* Styles */ } /* Samsung Galaxy S3 ----------- */ @media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){ /* Styles */ } @media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){ /* Styles */ } /* Samsung Galaxy S4 ----------- */ @media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){ /* Styles */ } @media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){ /* Styles */ } /* Samsung Galaxy S5 ----------- */ @media only screen and (min-device-width: 360px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){ /* Styles */ } @media only screen and (min-device-width: 360px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){ /* Styles */ }