CSS3-盒模型设计

来源:互联网 发布:大众软件官网 编辑:程序博客网 时间:2024/04/30 11:24

一、弹性盒模型

a)        注意在使用弹性盒模型的时候父元素必须要加display:box 或 display:inline-box

例:


b)        Box-orient 定义盒模型的布局方向

                                                                  i.             Horizontal 水平显示

                                                                ii.             vertical 垂直方向

例:

<!DOCTYPEhtml>

<html>

    <head>

       <metacharset="UTF-8">

       <title></title>

       <styletype="text/css">

           .box{height:100px;border:10pxsolid#000;padding:10px;display:-webkit-box;-webkit-box-orient:vertical;}

           .boxdiv{width:100px;height:100px;background: red; border:1pxsolid white;}

       </style>

    </head>

    <body>

       <divclass="box">

           <div>1</div>

           <div>2</div>

           <div>3</div>

           <div>4</div>

           <div>5</div>

       </div>

    </body>

</html>


c)        box-direction 元素排列顺序

                                                                  i.             Normal 正序

                                                                ii.             Reverse 反序

例:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.box{height: 100px; border: 10px solid #000;padding:10px;display: -webkit-box;-webkit-box-direction: reverse;
font-size: 20px;color: white;}
.box div{width: 100px; height: 100px;background: red; border: 1px solid white;}
</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</body>
</html>

d)        box-ordinal-group 设置元素的具体位置

例:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.box{height: 100px; border: 10px solid #000;padding:10px;display: -webkit-box;
font-size: 20px;color: white;}
.box div{width: 100px; height: 100px;background: red; border: 1px solid white;}
.box div:nth-of-type(1){-webkit-box-ordinal-group: 2;}
.box div:nth-of-type(2){-webkit-box-ordinal-group: 4;}
.box div:nth-of-type(3){-webkit-box-ordinal-group: 1;}
.box div:nth-of-type(4){-webkit-box-ordinal-group: 5;}
.box div:nth-of-type(5){-webkit-box-ordinal-group: 3;}

</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</body>
</html>

e)        Box-flex 定义盒子的弹性空间

                                                                  i.             子元素的尺寸=盒子的尺寸*子元素的box-flex属性值 / 所有子元素的box-flex属性值的和

例:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.box{height: 100px; border: 10px solid #000;padding:10px;display: -webkit-box;
font-size: 20px;color: white;}
.box div{ height: 100px;background: red; border: 1px solid white;}
.box div:nth-of-type(1){-webkit-box-flex: 1;}
.box div:nth-of-type(2){-webkit-box-flex: 2;}
.box div:nth-of-type(3){-webkit-box-flex: 3;}
.box div:nth-of-type(4){-webkit-box-flex: 4;}
.box div:nth-of-type(5){-webkit-box-flex: 5;}
</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</body>
</html>

f)        box-pack 对盒子富裕的空间进行管理

                                                                  i.             Start 所有子元素在盒子左侧显示,富裕空间在右侧

                                                                ii.             End 所有子元素在盒子右侧显示,富裕空间在左侧

                                                               iii.             Center 所有子元素居中

                                                               iv.             Justify 富余空间在子元素之间平均分布

例:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.box{height: 100px; border: 10px solid #000;padding:10px;display: -webkit-box;
font-size: 20px;color: white;-webkit-box-pack:justify;}
.box div{width:100px;height: 100px;background: red; border: 1px solid white;}

</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</body>
</html>

g)        box-align 在垂直方向上对元素的位置进行管理

                                                                  i.             Star 所有子元素在据顶

                                                                ii.             End 所有子元素在据底

                                                               iii.             Center 所有子元素居中

例:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
html{height: 100%;}
body{height: 100%;margin: 0;}
.box{height: 100%;padding:10px;display: -webkit-box;
font-size: 20px;color: white;-webkit-box-align:center;-webkit-box-pack: center;}
.box div{width:100px;height: 100px;background: red; border: 1px solid white;}

</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</body>
</html>

0 0
原创粉丝点击