CSS flex-grow 属性值说明
值 | 描述 |
---|---|
number | 指定项目(item)(item)相对于同一容器的其余部分的成长量会增加多少。默认值为0。 |
initial | 将属性设置为默认值。 |
inherit | 从其父元素继承此属性。 |
语法
flex-grow: number | initial | inherit;
flex-grow 属性的示例:
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> .box { width: 320px; height: 120px; border: 2px solid #cccccc; display: -webkit-flex; /* Safari */ display: flex; } /* Safari 6.1+ */ .box div:nth-of-type(1) { -webkit-flex-grow: 1; } .box div:nth-of-type(2) { -webkit-flex-grow: 2; } .box div:nth-of-type(3) { -webkit-flex-grow: 1; } .box div:nth-of-type(4) { -webkit-flex-grow: 1; } .box div:nth-of-type(5) { -webkit-flex-grow: 1; } /* Standard syntax */ .box div:nth-of-type(1) { flex-grow: 1; } .box div:nth-of-type(2) { flex-grow: 2; } .box div:nth-of-type(3) { flex-grow: 1; } .box div:nth-of-type(4) { flex-grow: 1; } .box div:nth-of-type(5) { flex-grow: 1; } </style> </head> <body> <h2>Flex-grow 属性示例</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>
结果
项目(item)(item)增长 6 像素的 flex-grow 属性示例:
<!DOCTYPE html> <html> <head> <title>The title of the document</title> <style> .box { width: 320px; height: 120px; border: 2px solid #cccccc; display: -webkit-flex; /* Safari */ display: flex; } /* Safari 6.1+ */ .box div:nth-of-type(1) { -webkit-flex-grow: 1; } .box div:nth-of-type(2) { -webkit-flex-grow: 6; } .box div:nth-of-type(3) { -webkit-flex-grow: 1; } .box div:nth-of-type(4) { -webkit-flex-grow: 1; } .box div:nth-of-type(5) { -webkit-flex-grow: 1; } /* Standard syntax */ .box div:nth-of-type(1) { flex-grow: 1; } .box div:nth-of-type(2) { flex-grow: 6; } .box div:nth-of-type(3) { flex-grow: 1; } .box div:nth-of-type(4) { flex-grow: 1; } .box div:nth-of-type(5) { flex-grow: 1; } </style> </head> <body> <h2>Flex-grow 属性示例</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>
flex-grow 属性指定项目(item)(item)相对于 flex 容器的其余项目(item)(item)将增长多少。
如果容器的所有项目(item)(item)都由 flex-grow 因子指定,则所有项目(item)(item)共享可用空间。
灵活项目(item)(item)的主要尺寸是它的高度或者宽度,这取决于 flex-direction 的值。
此属性是 CSS3 属性之一。
它与 flex-shrink 和 flex-basis 属性一起使用。
如果没有弹性项目(item)(item),则 flex-grow 属性不会有任何影响。
初始值 | 0. |
---|---|
应用于 | Flex项目(item)(item),包括流中的伪元素。 |
继承 | 无效 |
可动画的 | 是的。Items是可以动画的。 |
版本 | CSS3. |
DOM 语法 | object.style.flexgrow =“3”; |
日期:2020-06-02 22:14:30 来源:oir作者:oir