简体中文
flex-shrink 属性设置弹性元素在主轴方向的收缩系数。当所有子元素在主轴方向的尺寸之和大于容器时才会发生收缩,会根据元素的收缩系数进行收缩保证不溢出弹性容器。
| Web | Android | iOS | HarmonyOS | HarmonyOS(Vapor) |
|---|---|---|---|---|
| 4.0 | 3.9 | 4.11 | 4.61 | 5.0 |
flex-shrink: <number>;
| 平台 | 默认值 |
|---|---|
| uvue | 0 |
注意:W3C 默认值为:1
示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
示例
<template>
<view style="flex-grow: 1">
<view>
<text>flex-shrink</text>
<view style="
width: 250px;
height: 150px;
background-color: gray;
flex-direction: row;
">
<view class="common" style="background-color: red; flex-shrink: 1">
<text>1</text>
</view>
<view class="common" style="background-color: green; flex-shrink: 2">
<text>2</text>
</view>
<view class="common" style="background-color: blue; flex-shrink: 3">
<text>3</text>
</view>
</view>
</view>
</view>
</template>
<style>
.common {
width: 125px;
height: 50px;
justify-content: center;
align-items: center;
}
</style>