简体   繁体   English

如何同时应用宽度,最小宽度和最大宽度

[英]How to apply width, min-width and max-width at the same time

I have a div, and I am given 3 values for the width of the div. 我有一个div,并且为div的宽度指定了3个值。 The normal width of the div is 120px, the min width of the div is 90px, and the max width of the div is 150px. div的正常宽度为120px,div的最小宽度为90px,div的最大宽度为150px。 I guess I am asked to apply these values based on the width of the screen. 我猜我被要求根据屏幕的宽度应用这些值。 I would like to know how to write css for this? 我想知道如何为此编写CSS?

I have tried below code, but it seems my div is always 120px. 我试过下面的代码,但看来我的div始终为120px。

  .myDiv {
      width: 120px;
      max-width: 150px;
      min-width: 90px;
  }

Should I use media query? 我应该使用媒体查询吗?

Max-width and min-width as px will only have an impact if your width is used with percents % 仅当您的width与百分比%使用时, Max-widthmin-widthpx才会产生影响

(or other window based width like vw ). (或其他基于窗口的宽度,如vw )。

In your case I think indeed the best thing to do is use media queries. 对于您的情况,我认为确实最好的方法是使用媒体查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM