CSS3 Calc ()

Source: Internet
Author: User
Tags css preprocessor

What is calc ()?

Calc () is a new feature of CSS3 that can dynamically calculate length values, and any length value can be computed using calc (). 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 don't have to think about how much the element div's width value is, and leave this annoying task to the browser to calculate.

(It should be noted that the operators should keep spaces before and after use, although * and/these operators do not need to preserve spaces, but it is best to add them to the habit.) )


Grammar

In addition to the mobile browser, most browsers currently have good compatibility with Calc (), but they still need to prefix them before, for example:


Compatibility use

In Calc (), we can mix absolute units with relative units, such as:


Combined with the usage relative to absolute cells

When using Calc (), the computed value is the result of the expression itself, rather than the expression, when a mathematical operation is done using the CSS preprocessor, the given value is the result of an expression.


Then the browser resolves the value of calc () to the real Calc () expression


We can use Calc () to achieve vertical centering of elements


The typical solution is to use a negative margin to move one half of the height and width of the distance.


In fact, Calc () has a lot of practical uses, just to give an example, welcome to add

CSS3 Calc ()

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.