媒体查询 - 通用响应式模板

5


我想创建通用响应式模板,如果我想检测所有设备大小,需要使用哪些媒体查询?

3个回答

12

请查看此常用的CSS媒体查询断点

/*------------------------------------------
  Responsive Grid Media Queries - 1280, 1024, 768, 480
   1280-1024   - desktop (default grid)
   1024-768    - tablet landscape
   768-480     - tablet 
   480-less    - phone landscape & smaller
--------------------------------------------*/
@media all and (min-width: 1024px) and (max-width: 1280px) { }

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

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

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


/* Portrait */
@media screen and (orientation:portrait) { /* Portrait styles here */ }
/* Landscape */
@media screen and (orientation:landscape) { /* Landscape styles here */ }


/* CSS for iPhone, iPad, and Retina Displays */

/* Non-Retina */
@media screen and (-webkit-max-device-pixel-ratio: 1) {
}

/* Retina */
@media only screen and (-webkit-min-device-pixel-ratio: 1.5),
only screen and (-o-min-device-pixel-ratio: 3/2),
only screen and (min--moz-device-pixel-ratio: 1.5),
only screen and (min-device-pixel-ratio: 1.5) {
}

/* iPhone Portrait */
@media screen and (max-device-width: 480px) and (orientation:portrait) {
} 

/* iPhone Landscape */
@media screen and (max-device-width: 480px) and (orientation:landscape) {
}

/* iPad Portrait */
@media screen and (min-device-width: 481px) and (orientation:portrait) {
}

/* iPad Landscape */
@media screen and (min-device-width: 481px) and (orientation:landscape) {
}

我正在使用上述CSS,但我的网站按钮没有遵循该样式。有什么建议吗? - Dr. Mian
请提供jsfiddle以便更好地理解。 - Sender
我昨天做了一些搜索,发现asp.net按钮不遵守它。有什么建议或者我应该继续使用Bootstrap 3?非常感谢。 - Dr. Mian

2
我强烈推荐使用Bootstrap。开发速度更快,文档也非常完整。这是一个例子:http://getbootstrap.com/getting-started/。关于你的问题,你可以参考这个例子:
/*Anything outside of media queries is for MOBILE
  This is Mobile first approach.
*/

/* Small devices (tablets, 768px and up) */
@media (min-width: 768px) { ... }

/* Medium devices (desktops, 992px and up) */
@media (min-width: 992px) { ... }

/* Large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) { ... }


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接