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. Used to specify 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 advantage of Calc () is the use of fluid layouts. The width of the element can be calculated by Calc ().
What can 2.calc () do?
Calc () allows you to calculate the elements. You can calculate the width or height of a DIV element using percentages, EM, px, and REM unit values. Let's say "Width:calc (50% + 2em)", so you don't have to think about how much the width of the element div is, but leave this annoying task to the browser to calculate.
3.calc () syntax
The Calc () syntax is easy. Just like when we were kids, we learned to add (+), subtract (-), multiply (*), divide (/), and use mathematical expressions to represent:

. Elm {  width:calc (expression);}
where "expression" is an expression 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 be used in percentages, px, EM, REM and other units.
Able to mix and use various units for calculation;
There are "+" and "-" in the expression. There must be a space before and after it, such as "Widht:calc (12%+5em)" such as no space is wrong.

When there are "*" and "/" in the expression, there is no space before or after it, but it is recommended to leave a space.

5. Browser compatibility

The browser to calc () compatibility is good, in ie9+, ff4.0+, chrome19+, safari6+ are better supported, the same need to be in front of each browser manufacturer's identifier, but unfortunately, the mobile browser has not only "Firefox for Android 14.0 "Support, others are annihilated.
Everyone in the actual use. Same prefix that needs to be added to the browser
. 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.