Detailed calc () usage in CSS3

Source: Internet
Author: User
This article mainly introduced the detailed CSS 3 of the Calc () method, very good, with reference value, the need for friends can refer to, hope to help everyone.

The following snippet shows you The Calc () method in CSS3, as follows:


<p style= "width:100px; height:50px; background:red; " >  <p style= "width:100%; height:20px; margin:5px; background:green;" ></p></p>

[Ctrl + A All SELECT prompt: You can modify some of the code, and then press run]

As the code above, the preview can see that the red box is out of bounds, because in standard CSS, width is not a margin (the width of old IE contains margin).

In order to achieve the above effect, we will generally be in the middle of another layer of P (some people say, not to take the width:100% to take it?) Calmly, we are for example, in some cases, can not cancel width:100%. )

Is there any more convenient? Use Calc ().


<p style= "width:100px; height:50px; background:red; " >  <p style= "Width:calc (100%-10px); height:20px; margin:5px; background:green;" ></p></p>

[Ctrl + A All SELECT prompt: You can modify some of the code, and then press run]

Instructions for use

    • Support: + 、-、 *,/, support mixed

    • Support:%, px, EM, REM, etc.

    • +,-must have a space before and after, for example: Calc (100%-10px) is not correct, should be replaced by: Calc (100%-10px)

    • *,/front and back can not be space, but suggested there.

Support of

Mainstream desktop browsers are supported. Mobile browsers are said to have little support.

Related Article

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.