css3如何声明盒子弹性


本文摘自PHP中文网,作者醉折花枝作酒筹,侵删。

css3通过设置display属性的值为flex或inline-flex声明盒子弹性。弹性盒子由弹性容器(Flex container)和弹性子元素(Flex item)组成,弹性容器内包含了一个或多个弹性子元素。

本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

弹性盒子由弹性容器(Flex container)和弹性子元素(Flex item)组成。

弹性容器通过设置 display 属性的值为 flex 或 inline-flex将其定义为弹性容器。弹性容器内包含了一个或多个弹性子元素。

注意: 弹性容器外及弹性子元素内是正常渲染的。弹性盒子只定义了弹性子元素如何在弹性容器内布局。

弹性子元素通常在弹性盒子内一行显示。默认情况每个容器只有一行。

示例:

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

35

36

37

38

39

40

41

<!DOCTYPE html>

<html lang="en">

  <head>

    <meta charset="UTF-8" />

    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title>Document</title>

  </head>

  <!DOCTYPE html>

<html>

<head>

<style>

.flex-container {

    display: -webkit-flex;

    display: flex;

    width: 400px;

    height: 250px;

    background-color: lightgrey;

}

  

.flex-item {

    background-color: cornflowerblue;

    width: 100px;

    height: 100px;

    margin: 10px;

    text-align: center;

    line-height: 100px;

}

</style>

</head>

<body>

  

<div class="flex-container">

  <div class="flex-item">弹性容器 1</div>

  <div class="flex-item">弹性容器 2</div>

  <div class="flex-item">弹性容器 3</div>

</div>

  

</body>

</html>

</html>

效果:

WPU@_~W9%Z0S]E4N1Q$UD$V.png

推荐学习:css视频教程

以上就是css3如何声明盒子弹性的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

css3如何声明盒子弹性

更多相关阅读请进入《盒子弹性》频道 >>




打赏

取消

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

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

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

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

评论

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