Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use display box in css3

Shulou Source: shulou.com Published: 2022-06-03 11:53:09 09月11日 Update

Css3 how to use display box, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

One of the scenarios is as follows:

If we want to split the space occupied by the outer in different proportions with the internal level of 123elements, we might float the 123elements or set the display property to inline-block, and then set the width percentage to the width attribute to split the outer.

After using display:box, you can do this:

The code is as follows:

# outer {

Width:600px

Height:100px

Display:-moz-box

Display:-webkit-box

Display:box

}

# a1 {

Background:blue

-moz-box-flex:1

-webkit-box-flex:1

Box-flex:1

}

# a2 {

Background:green

-moz-box-flex:2

-webkit-box-flex:2

Box-flex:2

}

# a3 {

Background:yellow

-moz-box-flex:3

-webkit-box-flex:3

Box-flex:3

}

The effect is as follows:

The box-flex attribute in the child element is the percentage of the element, and for this attribute to take effect, the parent element must set display:box. Take A3 as an example, if A3 sets box-flex to 3, then its width is 600 * (3 / (1 / 2 / 3)) as 300px.

If one of the child elements has a fixed-width 100px set, the remaining 500px will participate in the scaling rules.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Element attribute width scale help usage different clear size code practice content scene this effect article novice more level Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MySQL Xiaomi OPPO Reno Microsoft