小白教程
所有教程
关于
Search
172.69.59.107
172.69.59.107
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Css3 pr flex grow”的源代码
本页内容
上一节:
Css3_pr_flex
下一节:
Css3_pr_flex_shrink
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:flex-grow}}[[Category:css reference|102]] = CSS flex-grow 属性 = [[css reference|CSS 参考手册]] 让第二个元素的宽度为其他元素的三倍: <sample title="" desc="" lang="html" hererun="1"> div:nth-of-type(1) {flex-grow: 1;} div:nth-of-type(2) {flex-grow: 3;} div:nth-of-type(3) {flex-grow: 1;} </sample> <run name=""> <!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> </run> == 浏览器支持 == 表格中的数字表示支持该属性的第一个浏览器的版本号。 紧跟在 -webkit-, -ms- 或 -moz- 后的数字为支持该前缀属性的第一个版本。 {| class="table table-striped table-hover" ! 属性 ! Chrome ! Internet Explorer / Edge ! Firefox ! Safari ! Opera |- | flex-grow | 29.021.0 -webkit- | 11.010.0 -ms- | 28.018.0 -moz- | 9.06.1 -webkit- | 17.0 |} == 定义和用法 == flex-grow 属性用于设置或检索弹性盒子的扩展比率。。 '''注意:'''如果元素不是弹性盒对象的元素,则 flex-grow 属性不起作用。 {| class="table table-striped table-hover" |width="50%"| 默认值: |width="50%"| 0 |- | 继承: | 否 |- | 可动画化: | 是。请参阅 [[css animatable|可动画化(animatable)]]。 <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <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: 1;} #main div:nth-of-type(3) {flex-grow: 1;} #myBlueDiv { animation:mymove 5s infinite; /*Safari 和 Chrome:*/ -webkit-animation:mymove 5s infinite; } @keyframes mymove { 50% {flex-grow:8;} } /*Safari 和 Chrome:*/ @-webkit-keyframes mymove { 50% {flex-grow:8;} } </style> </head> <body> <p>"blue DIV" 的 flex-grow 属性逐渐地从 1 变化到 8,然后再变回 1:<p> <div id="main"> <div style="background-color:coral;"></div> <div style="background-color:lightblue;" id="myBlueDiv"></div> <div style="background-color:khaki;"></div> </div> <p>在 CSS 中,flex-grow 属性是 <em>可动画化(animatable)</em> 的。</p> <p>Internet Explorer 10、Firefox 和 Opera 支持 CSS 动画。</p> <p>Safari 和 Chrome 通过带有前缀 -webkit-,支持 CSS 动画。</p> </body> </html> </run> |- | 版本: | CSS3 |- | JavaScript 语法: | object.style.flexGrow="5" <run name=""> <!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: 1;} #main div:nth-of-type(3) {flex-grow: 1;} </style> </head> <body> <div id="main"> <div style="background-color:coral;"></div> <div style="background-color:lightblue;" id="myBlueDiv"></div> <div style="background-color:khaki;"></div> </div> <p>点击“尝试一下”按钮设置蓝色 div 元素的 flexGrow 属性的值为 "5"。</p> <button onclick="myFunction()">尝试一下</button> <script> function myFunction() { document.getElementById("myBlueDiv").style.flexGrow = "5"; } </script> <p><b>注意:</b>Internet Explorer 和 Safari 不支持 flexGrow 属性。</p> </body> </html> </run> |} == CSS 语法 == <pre> flex-grow: number|initial|inherit;</pre> == 属性值 == {| class="table table-striped table-hover" ! 值 ! 描述 |- | number | 一个数字,规定项目相对于其他灵活的项目进行扩展的量。默认值是 0。 |- | initial | 设置该属性为它的默认值。请参阅 [[css initial|initial]]。 |- | inherit | 从父元素继承该属性。请参阅 [[css inherit|inherit]]。 |} == 相关文章 == CSS 参考手册:[[css3 pr flex|flex 属性]] CSS 参考手册:[[css3 pr flex basis|flex-basis 属性]] CSS 参考手册:[[css3 pr flex direction|flex-direction 属性]] CSS 参考手册:[[css3 pr flex flow|flex-flow 属性]] CSS 参考手册:[[css3 pr flex shrink|flex-shrink 属性]] CSS 参考手册:[[css3 pr flex wrap|flex-wrap 属性]] [[css reference|CSS 参考手册]]
返回至“
Css3 pr flex grow
”。
上一节:
Css3_pr_flex
下一节:
Css3_pr_flex_shrink