CSS3 Calc () feature small Peek

Source: Internet
Author: User

Before we want to achieve a perfect width adaptive input box is a good hassle, once also being a challenge to front-end technology. Similar common scenes also have 100% wide + border containers, and so on. In these situations, we have to be very careful because the performance of each browser may be inconsistent.

Now that Firefox and WebKit Support Calc (), we can also learn.

What does calc () do?

Calc () is the abbreviation for the word calculate (computed), a new length unit function of CSS3, which can be used in simple mathematical operations.

Well, CSS3 more and more advanced.

Operation rules

Calc () uses common mathematical rules of operation, but also provides more intelligent functionality:

    • Use "+" "-" "*" "/" arithmetic;
    • Can use the percentage, px, EM, REM and other units;
    • You can use a mix of units for calculation.

Instance:

Let's take a look at a few small examples to understand the Calc () function:

1
2
3
4
. box{
border:1px
						solid
						#ddd;
Width:calc (100%-2px)
}

The container width plus the border width is exactly 100%.

1
2
3
. box{
Width:calc (10em+20px)
}

width, 10em plus 20px.

1
2
3
4
5
6 7
. box{
margin-left:20px;
Width:calc (100%/3-20px);
Box:nth-child (3n) {
margin-left:0;
}

3 column width layout.

Browser support

Firefox 4.0+ has been spending support for Calc (), but to use the-moz-calc () private property, Chrome is also starting to support proprietary-WEBKIT-CALC () from the dev version, IE9 this time, The native support standard is not prefixed with the notation. Opera does not seem to support ~ ~

So if we want to use this attribute, remember to bring the compatibility of each browser.



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.