標籤:style blog color io strong ar art div cti
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>css3盒子模型</title> 5 <style> 6 .box3{ 7 width: 300px; 8 height: 100px; 9 /*設定css3盒子模型的父類*/10 display: -webkit-box;11 display: -moz-box;12 display: box;13 14 background-color: #1d89cf;15 }16 .box3>section{17 /*設定css3盒子模型的子類,將他們平分*/18 -webkit-box-flex: 1;19 -moz-box-flex: 1;20 box-flex: 1;21 22 border: 1px solid #fff;23 text-align: center;24 }25 </style>26 </head>27 28 <body>29 30 <div class="box3">31 <section>1</section>32 <section>2</section>33 <section>3</section>34 </div>35 36 </body>37 </html>
上面就是css3盒子模型最基本的一個代碼。
display:-*-box; 是定義盒子模型的父容器。
-*-box-flex: 1; 是定義盒子模型的子容器在父容器中的比例。
如是1,2,1,意思就是section1、2、3分別佔25%,50%,25%。
而-*-box有如下屬性:
-*-box-orient: horizontal | vertical | inline-axis | block-axis | inherit
用來確定父容器中的子容器的布局是水平布局還是垂直布局。(預設水平)
-*-box-direction: normal | reverse | inherit
用來確定子容器的排列順序,如是reverse,就是將123在頁面中變成了321的排列
-*-box-align:start(頂對齊) | end(底對齊) | center(置中對齊) | baseline | stretch(展開,展開到和父容器等高)
用來確定子容器的垂直對齊。
-*-box-pack: start | end | center | justify
用來確定子容器的水平對齊。
CSS3.0盒子模型:display:-webkit-box