css flex-grow属性怎么用


本文摘自PHP中文网,作者藏色散人,侵删。

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

css flex-grow属性怎么用

定义和用法

flex-grow 属性用于设置或检索弹性盒子的扩展比率。

注意:如果元素不是弹性盒对象的元素,则 flex-grow 属性不起作用。

默认值: 0

继承: 否

可动画化: 是。

版本: CSS3

JavaScript 语法:

1

object.style.flexGrow="5"

CSS 语法:

1

flex-grow: number|initial|inherit;

属性值

number 一个数字,规定项目将相对于其他灵活的项目进行扩展的量。默认值是 0。

initial 设置该属性为它的默认值。

inherit 从父元素继承该属性。

实例

让第二个元素的宽度为其他元素的三倍:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

<!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>

效果:

6f9212f30a2e63ace2b6024b78d49e0.png

以上就是css flex-grow属性怎么用的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

css如何实现始终将footer固定在底部

css怎么把按钮上移

css中display:hidden和display:none有什么区别

css如何让图片和文字垂直居中对齐

css什么时候用class和id

css quotes属性怎么用

css优化策略介绍

css flex-grow属性怎么用

css怎么设置黑体

css怎么隐藏table

更多相关阅读请进入《css》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...