温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

css中flex-grow属性的使用方法

发布时间:2020-09-24 11:06:56 来源:亿速云 阅读:268 作者:小新 栏目:web开发

小编给大家分享一下css中flex-grow属性的使用方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

css flex-grow属性用于设置或检索弹性盒子的扩展比率,CSS语法是flex-grow: number|initial|inherit;如果元素不是弹性盒对象的元素,则flex-grow属性不起作用。

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属性的使用方法

看完了这篇文章,相信你对css中flex-grow属性的使用方法有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI