聊聊css中box-align和box-pack属性的用法


本文摘自PHP中文网,作者青灯夜游,侵删。

【推荐教程:CSS视频教程 】

css中的box-align与box-pack属性可以用来设置框内元素的位置。

注意: 需要对齐的元素的父元素dispaly的值必须为box

box-align值为center时,子元素为垂直居中

box-pack 属性规定当框大于子元素的尺寸,在何处放置子元素。该属性规定水平框中的水平位置,以及垂直框中的垂直位置。

对于水平框,box-pack值为center时,子元素水平居中

HTML代码:

1

2

3

4

5

<div id="parent1">

    <div id="div1">

        div1

    </div>

</div>

CSS代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

div{

    border: solid black 1px;

}

#parent1{

    width: 100%;

    height: 500px;

    display: -webkit-box;

    display: -moz-box;

    -webkit-box-align: center;

    -moz-box-align: center;

    -moz-box-pack: center;

    -webkit-box-pack: center;

}

当box-pack值为justify时,子元素分散对齐

HTML代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

<div id="parent2">

    <div id="div2">

        div2

    </div>

    <div id="div3">

        div3

    </div>

    <div id="div4">

        div4

    </div>

    <div id="5">

        div5

    </div>

    <div id="div6">

        div6

    </div>

</div>

CSS代码:

1

2

3

4

5

6

7

8

9

10

#parent2{

    width: 100%;

    height: 500px;

    display: -webkit-box;

    display: -moz-box;

    -webkit-box-align: center;

    -moz-box-align: center;

    -moz-box-pack: justify;

    -webkit-box-pack: justify;

}

效果如下:

1.png

更多计算机编程相关知识,请访问:编程视频!!

以上就是聊聊css中box-align和box-pack属性的用法的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

css哪些属性可以继承

css中无继承性的属性有哪些

css transform-style属性怎么用

如何解决eclipse css文件乱码问题

详解css contain新特性如何控制页面重绘与重排

css怎么清除空白

css实现文字描边以及倒影效果

css border-top-color属性怎么用

css怎么让背景图片不重复

css子类选择器是什么

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




打赏

取消

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

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

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

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

评论

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