Calc in CSS3 ()

Source: Internet
Author: User

1. What is calc ()?
Calc is an abbreviation for the English word Calculate (calculation) and is a new feature of CSS3 that specifies the length of the element. For example, you can use Calc () to set dynamic values for attributes such as border, margin, pading, font-size, and width for an element. The biggest benefit of Calc () is that the width of the element can be calculated by Calc () using the fluid layout.
what can 2.calc () do?
Calc () allows you to calculate the elements, you can give a DIV element, using percentages, EM, px and REM unit values to calculate its width or height, such as "Width:calc (50% + 2em)", so you do not have to consider the element div width value is exactly how much, And this annoying task to the browser to calculate.
3.calc () syntax
The Calc () syntax is very simple, as we learned to add (+), subtract (-), multiply (*), and (/) as a child, using mathematical expressions to represent:
. Elm {  width:calc (expression);}
where "expression" is an expression that is used to calculate the length of an expression.
arithmetic rules for 4.calc ()
Calc () uses common mathematical rules, but it also provides more intelligent functionality:
Use "+", "-", "*" and "/" arithmetic;
can use percentages, px, EM, REM and other units;
Can be mixed with various units for calculation;
When there are "+" and "-" in the expression, there must be a space before and after it, such as "Widht:calc (12%+5em)", which is not the correct way to make a blank;

When there are "*" and "/" in an expression, there can be no spaces before or after it, but it is recommended that you leave a space.

5. Browser compatibility

The browser to calc () compatibility is good, in ie9+, ff4.0+, chrome19+, safari6+ are better supported, the same needs to be preceded by the browser manufacturer's identifier, but unfortunately, the mobile browser has not only "Firefox for Android 14.0 "Support, others are annihilated.
You also need to add a browser prefix when you are actually using it.
. Elm {  /*firefox*/  -moz-calc (expression);  /*chrome safari*/  -webkit-calc (expression);  /*standard *  /calc (expression);}


Calc in CSS3 ()

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.