


An example introduction to the box-flex flexible box attribute layout in CSS3
Flex layout is undoubtedly the most powerful layout method for today's Web pages, and the box-flex flexible box model is one of its representatives. Here we will explain the box-flex flexible box model layout in CSS3 with an example
box-flex is a newly added box model attribute in CSS3. Its appearance breaks the floating layout we often use and achieves vertical equal height, horizontal division, and proportional division. But it has certain limitations. In Firefox and Chrome browsers, they need to be defined using their private attributes: Firefox (-moz), Chrome (-webkit).
1. The box-flex attribute
box-flex mainly allows the child container to be divided according to certain rules according to the width of the parent container.
<p class="box"> <p class="col_1">111</p> <p class="col_2">222</p> <p class="col_3">333</p> </p> <style type="text/css"> .box { display:box; display:-webkit-box; display:-moz-box; background-color:#fff; width:500px; height:100px; border:1px solid #333; margin:0 auto; } .col_1 { box-flex:1; -moz-box-flex:1; -webkit-box-flex:1; background-color:#ffc; } .col_2 { background-color:#ccf; box-flex:2; -moz-box-flex:2; -webkit-box-flex:2; } .col_3 { background-color:#fcf; box-flex:2; -moz-box-flex:2; -webkit-box-flex:2; } </style>
Note:
The parent container must be defined as display:box, and its child containers can be divided (if display:box is set Then the container is an inline element, and using margin:0 auto to center it is invalid under Firefox. It needs to be controlled through the text-align:center; of the parent container, but it is possible under Chrome)
As mentioned above. In the example, the three sub-blocks are set to 1, 2, and 2 respectively, which means that the parent container is divided into 5 parts, occupying 1/5 (100px), 2/5 (200px), and 2/5 of the width of the parent structure respectively. (200px).
The above is divided according to the proportion. If one or more sub-containers have a fixed width set and other sub-containers have not been set, then the width is calculated according to the width, and the remaining parts are calculated according to the above method. calculate.
.col_3 { background-color:#fcf; width:50px;/*设置宽度为50px*/ }
When there is a gap in the sub-container, the width of their equal parts needs to be subtracted from the middle margin, and then divided equally in proportion.
.col_2 { background-color:#ccf; box-flex:2; -moz-box-flex:2; -webkit-box-flex:2; margin:0 20px; }
##2. Box attribute
What is mentioned above Let’s talk about how box-flex divides the width of the parent container. Now let’s talk about what the box attributes in the parent container include. box-orient, box-direction, box-align, box-pack, box-lines
1. box-orient
box-orient is used to determine the child container in the parent container Whether the arrangement is horizontal or vertical, the optional attributes are as follows: horizontal | vertical | inline-axis | block-axis | inherit
The horizontal and inline-axis properties have the same effect, and they can arrange the containers horizontally. Horizontally arranged styles are also rendered by default. When the parent container sets the height, the height of its child container is invalid under firefox, but valid under chroma.
.col_1 { height:50px; } .col_2 { height:80px; }
.box { /*未设置高度*/ } .col_1 { height:50px; } .col_2 { height:80px; } .col_3 { /*未设置高度*/ }
2、box-direction
box-direction用来确定父容器里面的子容器排列顺序,具有以下属性:
normal | reverse | inherit
normal是默认值,如上面测试结果。
reverse表示反转,其表现方式跟normal相反,呈现为3、2、1
3、box-align
box-align表示父容器里面子容器的垂直对齐方式,属性值为:
start | end | center | baseline | stretch
start、baseline展示效果
end展示效果
center展示效果
stretch展示效果,(谷歌下面如start)
4、box-pack
box-pack表示父容器里面子容器的水平对齐方式,可选参数如下所示:
start | end | center | justify
css代码
.box { display:box; display:-webkit-box; display:-moz-box; background-color:#fff; width:500px; border:1px solid #333; margin:0 auto; height:100px; -webkit-box-pack:start; -moz-box-pack:start; box-pack:start; } .col_1,.col_2,.col_3{ width:100px; }
start:在box-pack表示水平居左对齐,如下所示:
end:在box-pack表示水平居右对齐,如下图所示
center:在box-pack表示水平居中对齐,如下图所示
justify:在box-pack表示两边对齐试
The above is the detailed content of An example introduction to the box-flex flexible box attribute layout in CSS3. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to achieve wave effect with pure CSS3? This article will introduce to you how to use SVG and CSS animation to create wave effects. I hope it will be helpful to you!

This article will show you how to use CSS to easily realize various weird-shaped buttons that appear frequently. I hope it will be helpful to you!

Two methods: 1. Using the display attribute, just add the "display:none;" style to the element. 2. Use the position and top attributes to set the absolute positioning of the element to hide the element. Just add the "position:absolute;top:-9999px;" style to the element.

In CSS, you can use the border-image attribute to achieve a lace border. The border-image attribute can use images to create borders, that is, add a background image to the border. You only need to specify the background image as a lace style; the syntax "border-image: url (image path) offsets the image border width inward. Whether outset is repeated;".

How to create text carousel and image carousel? The first thing everyone thinks of is whether to use js. In fact, text carousel and image carousel can also be realized using pure CSS. Let’s take a look at the implementation method. I hope it will be helpful to everyone!

Implementation method: 1. Use the ":active" selector to select the state of the mouse click on the picture; 2. Use the transform attribute and scale() function to achieve the picture magnification effect, the syntax "img:active {transform: scale(x-axis magnification, y Axis magnification);}".

In CSS3, you can use the "animation-timing-function" attribute to set the animation rotation speed. This attribute is used to specify how the animation will complete a cycle and set the speed curve of the animation. The syntax is "element {animation-timing-function: speed attribute value;}".

The animation effect in css3 has deformation; you can use "animation: animation attribute @keyframes ..{..{transform: transformation attribute}}" to achieve deformation animation effect. The animation attribute is used to set the animation style, and the transform attribute is used to set the deformation style. .
