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

发布时间:2022-05-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了聊聊css中box-align和box-pack属性的用法脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

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

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

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

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

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

HTML代码:

<div id="parent1">
    <div id="div1">
        div1
    </div>
</div>

CSS代码:

 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代码:

<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代码:

 #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;
}

效果如下:

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

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

以上就是聊聊css中box-align和box-pack属性的用法的详细内容,更多请关注脚本宝典其它相关文章

脚本宝典总结

以上是脚本宝典为你收集整理的聊聊css中box-align和box-pack属性的用法全部内容,希望文章能够帮你解决聊聊css中box-align和box-pack属性的用法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: