CSS3 Flexible Box Module-1

Source: Internet
Author: User

Some new box model parameters are introduced in the CSS3 standard. Based on CSS2, We can flexibly adjust the size and location of each container on the page. For more information, see this document.

Through learning and testing, I found that this new box model layout brings great benefits to the establishment of Adaptive Layout pages. In this article, all my examples are based on the following HTML code:

<Body>
<Div id = "box1"> 1 </div>
<Div id = "box2"> 2 </div>
<Div id = "box3"> 3 </div>
</Body> container Arrangement

In general, all containers on the page are arranged in the order of loading. With the functions provided by CSS3, we can change the container display position without changing the HTML structure, which not only brings great convenience to the layout, we can also use these features for traffic shaping.

When using the Flexible Box Module, we need to set the Display attribute of its parent container to box or inline-box.

Horizontal and vertical distribution

We can use the box-orient attribute to specify the distribution axis of the container. When the value of this attribute is vertical, its sub-containers are vertically distributed (or block-axis ), when the value is horizontal, its sub-containers are horizontally distributed (or inline-axis ). In the first example of this article, I used the following CSS:

# Exemple1. content {
-Moz-box-orient: horizontal;
-Webkit-box-orient: horizontal;
Box-orient: horizontal;
}

# Exemple1. boite {
-Moz-box-flex: 1;
-Webkit-box-flex: 1;
Box-flex: 1;
}

For the specific effect, you can see this DEMO. The three sub-Div containers are all horizontally tied.

Note: This effect can also be achieved through Display: inline; theoretically in CSS2, but no one will do this due to some browser bugs.

Reverse Order

The box-direction attribute allows us to change the display sequence of containers at will. We know that by default, block-level elements are arranged from top to bottom according to the loading order, and inline-level elements are arranged from left to right, but now we can use the box-direction attribute to display the last loaded block-level elements at the top, and the last loaded inline-level elements on the left.

However, when using this attribute, you must note that it may change some attributes of the element to produce some uncontrollable results.

In the second example, I used the following CSS:

# Exemple2. content {
-Moz-box-orient: vertical;
-Moz-box-direction: reverse;

-Webkit-box-orient: vertical;
-Webkit-box-direction: reverse;

Box-orient: vertical;
Box-direction: reverse;
}

# Exemple2. boite {
-Moz-box-flex: 1;
-Webkit-box-flex: 1;
Box-flex: 1;
}

You can see this DEMO. We can find that the order of containers is changed without changing the HTML structure.

  • 2 pages in total:
  • Previous Page
  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.