Border padding margin, the difference among them

Source: Internet
Author: User

In CSS, they are all box-type attributes used to indicate the distance.
Margin: blank outside the border of the layer, padding: blank between the border of the layer and the content of the layer, border: border, content: content.

The border attribute (border) is used to set the edge of an element.
The margin attribute (margin) is used to set the distance between the edge of an element's space and adjacent elements.
The gap attribute (padding) is used to set the distance from the element content to the element boundary.
These three attributes belong to the box type attribute in CSS.


  1. border style border
Syntax: border-width | border-style | border-color
Parameter: This attribute is a composite attribute. See the attributes of each parameter.
The default value is medium none. The default value of border-color is text color. To use this attribute, you must first set the height or width attribute of the object, or set the position attribute to absolute.
Example: p {border: thick double yellow ;}

  2. Blank Padding. Syntax: padding: length
Parameter: length value or percentage composed of floating-point numbers and unit identifiers. The percentage is based on the width of the parent object. See length units.
Padding Abbreviations:
Search for or set the patch margins on the four sides of an object. If all four parameter values are provided, the top-right-bottom-left parameters are added to the four sides. If only one edge is provided, all four edges are used. If two are provided, the first is used for top-bottom, and the second is used for left-right. If three are provided, the first is used for the top, the second is used for the left-right, and the third is used for the bottom.
Example: p {padding: 36pt 24pt 36pt ;}

  3. Margin margin, Syntax: Margin: auto | length
Parameters:
Auto: the value of the relative edge.
Length: The length value or percentage composed of floating point numbers and unit identifiers. The percentage is based on the height of the parent object.
  Margin Abbreviations:
If all four parameter values are provided, the top-right-bottom-left parameters are added to the four sides. If only one is provided, all the four sides are used. If two are provided, the first is used for top-bottom, and the second is used for left-right. If three are provided, the first is used for the top, the second is used for the left-right, and the third is used for the bottom.
The Margin attributes of margin include: margin-top --- top margin, margin-right --- right Margin, margin-bottom --- bottom margin, and margin-left --- left margin.
Example:
Body {margin: 36pt 24pt 36pt ;}
Body {margin: 11.5% ;}
Body {margin: 10% 10% 10% 10% ;}

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.