flex-shrink

CSS flex-shrink Property

The flex-shrink property specifies how much the item will shrink relative to the rest of the items of the flex container. If the size of items is larger than the container, items shrink to fit the flex container. When flex-shrink property is not included in the flex shorthand declaration, the value is set to 1 by default. If there are no flexible items,flex-shrink property won’t have any effect.

The flex-shrink property is one of the CSS3 properties.

The flex-shrink factor is multiplied by the flex-basis when negative space is distributed.

类目类目
Initial Value1
Applies toFex items, including in-flow pseudo-elements.
InheritedNo.
AnimatableYes. Items are animatable.
VersionCSS3
DOM Syntaxobject.style.flexShrink = “4”;

Syntax

Syntax

flex-shrink: number | initial | inherit;

Example of the flex-shrink property:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .box {
        width: 320px;
        height: 120px;
        border: 1px dotted #666666;
        display: -webkit-flex; /* Safari */
        display: flex;
      }
      .box div {
        -webkit-flex-grow: 1; /* Safari 6.1+ */
        -webkit-flex-shrink: 3; /* Safari 6.1+ */
        -webkit-flex-basis: 100px; /* Safari 6.1+ */
        flex-grow: 1;
        flex-shrink: 3;
        flex-basis: 100px;
      }
      .box div:nth-of-type(2) {
        -webkit-flex-shrink: 7; /* Safari 6.1+ */
        flex-shrink: 7;
      }
    </style>
  </head>
  <body>
    <h2>Flex-shrink property example</h2>
    <div class="box">
      <div style="background-color: #eeeeee;"></div>
      <div style="background-color: #1c87c9;"></div>
      <div style="background-color: #8ebf42;"></div>
      <div style="background-color: #cccccc;"></div>
      <div style="background-color: #666666;"></div>
    </div>
  </body>
</html>

Result

Values

Values

ValueDescriptionPlay it
numberSpecifies how much the item will shrink relative to the rest of the flexible items of the same container. Default value is 1.Play it »
initialSets the property to its default value.Play it »
inheritInherits this property from its parent element.


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

扫一扫,反馈当前页面

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