CSS3 using Calc () to do arithmetic (turn)

Source: Internet
Author: User

Calc is an abbreviation for the English word Calculate (calculation) and is a new feature of CSS3 that specifies the length of the element. This function allows you to perform simple arithmetic calculations, such as calculating the length and width of an element, eliminating the JavaScript code you write that is not easy to maintain. This function supports all simple basic arithmetic operations, including subtraction.

When there are "+" and "-" in the expression, there must be a space before and after it, such as "Widht:calc (12%+5em)" is not a blank notation is wrong, there are "*" and "/" in the expression, there can be no space before and after it, but it is recommended to leave a space. The browser to calc () compatibility is good, in ie9+, ff4.0+, chrome19+, safari6+ are better supported, the same need to be preceded by the browser manufacturer's identifier, but unfortunately, the mobile browser is mostly not supported, currently only " Firefox for Android 14.0 "support.

For example, you want to create an element that fills its parent element, but leaves a portion of the pixel wide for other uses:

{     width: 100%;       Border: solid black 1px;      position: relative;} {position: absolute;               left: 100px;       width: calc (90%-100px);     background-color: #ff8;       text-align: Center;  

Pretty, isn't it? For more detailed information, please refer to the CSS Calc specification.

It is more and more clear that CSS has matured into some ways to replace JavaScript, greatly simplifying the work of web developers. If you don't start taking advantage of these features, that's just being silly.

CSS3 using Calc () to do arithmetic (turn)

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.