CSS flex-grow 属性
让第二个元素的宽度为其他元素的三倍:
<!DOCTYPE html>
<html>
<head>
<style>
#main {
width: 350px;
height: 100px;
border: 1px solid #c3c3c3;
display: flex;
}
#main div:nth-of-type(1) {
flex-grow: 1;
}
#main div:nth-of-type(2) {
flex-grow: 3;
}
#main div:nth-of-type(3) {
flex-grow: 1;
}
#main div:nth-of-type(4) {
flex-grow: 1;
}
#main div:nth-of-type(5) {
flex-grow: 1;
}
</style>
</head>
<body>
<div id="main">
<div style="background-color:coral;"></div>
<div style="background-color:lightblue;"></div>
<div style="background-color:khaki;"></div>
<div style="background-color:pink;"></div>
<div style="background-color:lightgrey;"></div>
</div>
<p><b>注意:</b> Internet Explorer 10 及更早版本浏览器不支持 flex-grow 属性。</p>
<p><b>注意:</b> Safari 6.1 及更新版本通过 -webkit-flex-grow 属性支持该属性。</p>
</body>
</html>
浏览器支持
表格中的数字表示支持该属性的第一个浏览器的版本号。
紧跟在 -webkit-, -ms- 或 -moz- 后的数字为支持该前缀属性的第一个版本。
| 属性 | |||||
|---|---|---|---|---|---|
| flex-grow | 29.0 21.0 -webkit- |
11.0 10.0 -ms- |
28.0 18.0 -moz- |
9.0 6.1 -webkit- |
17.0 |
定义和用法
flex-grow 属性用于设置或检索弹性盒的扩展比率。。
注意:如果元素不是弹性盒对象的元素,则 flex-grow 属性不起作用。
| 默认值: | 0 |
|---|---|
| 继承: | 否 |
| 可动画化: | 是。请参阅 可动画化(animatable)。 - 尝试一下 - |
| 版本: | CSS3 |
| JavaScript 语法: | object.style.flexGrow="5" - 尝试一下 - |
CSS 语法
flex-grow: number|initial|inherit;
属性值
| 值 | 描述 |
|---|---|
| number | 一个数字,规定项目将相对于其他灵活的项目进行扩展的量。默认值是 0。 |
| initial | 设置该属性为它的默认值。请参阅 initial。 |
| inherit | 从父元素继承该属性。请参阅 inherit。 |
相关文章
CSS 参考手册:flex 属性
CSS 参考手册:flex-basis 属性
CSS 参考手册:flex-direction 属性
CSS 参考手册:flex-flow 属性
CSS 参考手册:flex-shrink 属性
CSS 参考手册:flex-wrap 属性
CSS 参考手册
CSS 参考手册