CSS 您将如何为多种屏幕尺寸编写媒体查询?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8594876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How would you write media queries for multiple screen sizes?
提问by Jitendra Vyas
If i want
如果我想要
body {font-size:18 px}
for 1900 and above
body {font-size:18 px}
1900及以上
body {font-size:16 px}
for 1024 and 1900
body {font-size:16 px}
1024 和 1900
body {font-size:14 px}
for 768 to 1023
body {font-size:14 px}
768 至 1023
body {font-size:12 px}
for 320 to 767
body {font-size:12 px}
320 至 767
body {font-size:11 px}
for 0 to 320
body {font-size:11 px}
0 到 320
I just given and example for question.
我刚刚给出了问题的例子。
回答by Simone
This should do the work
这应该做的工作
@media only screen and (min-width: 320px) { body{ font-size: 12px; } }
@media only screen and (min-width: 768px) { body{ font-size: 14px; } }
@media only screen and (min-width: 1024px) { body{ font-size: 16px; } }
@media only screen and (min-width: 1900px) { body{ font-size: 18px; } }
回答by Blender
I love this blog/website, as it is a good resource for CSS3 and nifty tricks:
我喜欢这个博客/网站,因为它是 CSS3 和漂亮技巧的好资源:
/* 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 */
}
/* 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 */
}
回答by Touhid Rahman
Apply this code.
应用此代码。
@media only screen and (max-width:319px) { body{font-size:11px}}
@media only screen and (min-width:320px) and (max-width:767px) { body{font-size:12px} }
@media only screen and (min-width:768px) and (max-width:1023px) { body{font-size:14px} }
@media only screen and (min-width:1024px) and (max-width:1899px) { body{font-size:16px} }
@media only screen and (min-width:1900px) { body{font-size:18px} }
回答by Sagar Jethi
Media queries a use for change design of different screens using CSS
媒体查询使用 CSS 更改不同屏幕的设计
Following different devide for design :https://gist.github.com/sagarjethi/9fb395ee4422cccce625dcde5349fa52
遵循不同的设计:https: //gist.github.com/sagarjethi/9fb395ee4422cccce625dcde5349fa52
/* 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 */
}
回答by hradac
You could use media queries. For example your font size for 1024 to 1900 would be set like this:
您可以使用媒体查询。例如,1024 到 1900 的字体大小将设置如下:
@media screen and (max-width: 1900px){
body{font-size:16px;}
}
For a more thorough explanation see responsive web design: http://www.alistapart.com/articles/responsive-web-design/
有关更详尽的解释,请参阅响应式网页设计:http: //www.alistapart.com/articles/responsive-web-design/