Calc () and css3calc () in css3 ()

Source: Internet
Author: User

Calc () and css3calc () in css3 ()
1. What is calc ()?
Calc is the abbreviation of the English word calculate (calculation). It is a new feature of css3 to specify the length of an element. For example, you can use calc () to set dynamic values for attributes such as border, margin, pading, font-size, and width of an element. The biggest benefit of calc () is that it is used in the Fluid layout and can be calculated using calc () to obtain the width of the element.
2. What can calc () do?
Calc () allows you to calculate the elements. You can calculate the width or height of a div element based on the percentage, em, px, and rem unit values. For example, "width: calc (50% + 2em) ", so you don't have to consider the actual width of the element div, but leave this annoying task to the browser for calculation.
3. calc () syntax
The calc () syntax is very simple. It is represented by mathematical expressions like adding (+), subtraction (-), multiplication (*), and Division (/) when we were a child:

.elm {  width: calc(expression);}
"Expression" is an expression used to calculate the length.
4. calc () calculation rules
Calc () uses general mathematical calculation rules, but also provides more intelligent functions:
Use four arithmetic operations: "+", "-", "*", and;
Units such as percentage, px, em, and rem can be used;
Various units can be used for calculation;
When the expressions contain "+" and "-", spaces must exist before and after the expressions, such as "widht: calc (12% + 5em;

When the expression contains "*" and "/", there can be no spaces before and after it, but it is recommended to leave spaces.

5. browser compatibility

The browser has good compatibility with calc (), and is well supported in IE9 +, FF4.0 +, Chrome19 +, and Safari6 +, we also need to add the identifiers of various browser vendors to the front of the browser, but unfortunately, the mobile browser does not only support "firefox for android 14.0", and the rest are not supported.
In actual use, you also need to add the browser prefix.
 .elm {  /*Firefox*/  -moz-calc(expression);  /*chrome safari*/  -webkit-calc(expression);  /*Standard */  calc(expression); }


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.