How to use the Calc () method of CSS3

Source: Internet
Author: User
This time to bring you CSS3 of the Calc () method How to use, CSS3 of the Calc () method used to note what, the following is the actual case, together to see.

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.

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

Redraw and rearrange how to use

How to use CSS settings to record user passwords

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.