min-width

CSS min-width Property

The min-width property sets the minimum width of an element. This property prevents the width property’s value from becoming smaller than the value specified for min-width.

Meanwhile, the min-width property overrides width property and CSS max-width property.

The property takes a CSS length (px, pt, em, and so on), or a percentage.

Negative length values are illegal.

类目类目
Initial Value0
Applies toAll elements, but non-replaced inline elements, table rows, and row groups.
InheritedNo.
AnimatableYes. Width is animatable.
VersionCSS2
DOM Syntaxobject.style.minWidth = “200px”;

Syntax

Syntax

min-width: none | length | initial | inherit;

Example of the min-width property:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      div {
        width: 10px;
        min-width: 70%;
        background-color: #1c87c9;
        color: #ffffff
      }
    </style>
  </head>
  <body>
    <div>The min-width of this text is defined as 70%.</div>
  </body>
</html>

Result

Here the minimum width of the element is 10cm:

Example of the min-width property specified in “cm”:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      span {
        background-color: #ccc;
        min-width: none;
      }
      .example {
        min-width: 10cm;
        display: inline-block;
      }
    </style>
  </head>
  <body>
    <h2>Min-width property example</h2>
    <h3>Min-width: none:</h3>
    <span>Minimum width is set to none.</span>
    <h3>min-width: 10cm:</h3>
    <span class="example">Minimum width is set to 10cm.</span>
  </body>
</html>

Values

Values

ValueDescriptionPlay it
autoThe browser calculates and selects a min-width for the given element.Play it »
lengthDefines minimum width in px, pt, cm, etc. Default value is 0.Play it »
%Sets the minimum width in % of containing element.Play it »
initialMakes the property use its default value.Play it »
inheritInherits the property from its parents element.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部