您如何为多种屏幕尺寸编写媒体查询?

时间:2022-12-09 13:36:43

If i want

如果我想

body {font-size:18 px} for 1900 and above

1900及以上的身体{font-size:18 px}

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} for 768 to 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.

我刚才给出了问题的例子。

4 个解决方案

#1


13  

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; } }

#2


9  

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 */
}

#3


1  

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} }

#4


0  

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/

#1


13  

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; } }

#2


9  

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 */
}

#3


1  

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} }

#4


0  

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/