css flex-grow属性如何用
发布时间:09/01 来源:未知 浏览:
关键词:
css flex-grow属性如何用?
定义和用途
flex-grow 属性用于设定或检索弹性盒子的扩展比率。
留意:假如元素不是弹性盒对象的元素,则 flex-grow 属性不起作用。
默许值: 0
继承: 否
可动画化: 是。
版本: CSS3
JavaScript 语法:
object.style.flexGrow="5"
CSS 语法:
flex-grow: number|initial|inherit;
属性值
number 一个数字,规定项目将相关于其他灵敏的项目停止扩展的量。默许值是 0。
initial 设定该属性为它的默许值。
inherit 从父元素继承该属性。
实例
让第二个元素的宽度为其他元素的三倍:
<!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>
结果:
以上就是css flex-grow属性如何用的具体内容,更多请关注百分百源码网其它相关文章!