Difference between the margin and padding attributes in CSS

Source: Internet
Author: User

Margin: blank outside the border of the layer

Padding: blank between the border of the layer and the content of the layer

 

Padding-top padding-left padding-Right padding-bottom

Margin-top margin-left margin-right margin-bottom

 

The width of the gap between the upper and lower sides is the same

. D1 {padding: 1 cm}

. D1 {margin: 1 cm}

 

You can also set the gap separately. The order is top, right, bottom, left. Example:

. D1 {padding: 1 cm 2 cm 3 cm 4 cm}

. D1 {margin: 1 cm 2 cm 3 cm 4 cm}

The above Code indicates that the upper gap is 1 cm, the right gap is 2 cm, the lower gap is 3 cm, and the left gap is 4 cm.

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.