css 最小宽度和最大宽度

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css 最小宽度和最大宽度相关的知识,希望对你有一定的参考价值。

@media only screen and (min-width: 330px)  {...}
/* If [device width] is greater than or equal to [330px], then do {...} */

/*-------------------------------------------------------*/

@media only screen and (max-width: 330px)  {...}
/* If [device width] is less than or equal to [330px], then do {...} */

-------------------------------------------------------

/*
This means that max-width is the maximum width at which these styles will be shown. A screen wider than the specified number will not use the styles associated with that rule. Similarly, min-width is the minimum width at which these styles will be shown. A screen narrower than the specified number will not use the styles associated with that rule.
*/

/*-------------------------------------------------------*/

@media only screen and (max-width: 640px)  {...}
@media only screen and (max-width: 479px)  {...}

/*
I didn't realize it at the time but in the example above, the second media query actually trumps the first due to standard CSS inheritance rules. By rights, the first triggers any device with a width less than 640px and the second triggers any device with a width less than 479px. So if you truly want to trump the first, you need to make sure that you overwrite all CSS properties under the second condition.
*/

/*-------------------------------------------------------*/

/* A more succinct approach would be to do the following: */

@media only screen and (min-width:480px) and (max-width: 640px)  {...}
@media only screen and (max-width: 479px)  {...}

/*
The only difference is that we added a min-width condition to the first media query. This now separates the two queries so that one doesn't necessarily have to trump the other. The first is now saying anything greater than 480px and less than 640px, the other is simply stating anything less than 479px.
*/

以上是关于css 最小宽度和最大宽度的主要内容,如果未能解决你的问题,请参考以下文章

CSS 最大/最小宽度和最大/最小高度

css IE6のための最小高度,最小宽度,最大高度,最大宽度。

CSS ie6的最小宽度/最大宽度

CSS IE的最小/最大高度/宽度解决方法

CSS IE的最小/最大高度/宽度解决方法

使用 css 变量(没有 SASS/LESS)设置媒体查询的最小/最大宽度?