CSS learning-margin and padding

Source: Internet
Author: User
ArticleDirectory
  • Description

CSSMarginAttribute

MarginAttribute is a short attribute used to set all attributes with four margins in a declaration.

Description

This short attribute sets allMarginOr set the width of the top and outer margins of each side.

The vertical adjacent outer margins of block-level elements are merged, while the intra-row elements do not actually occupy the upper and lower margins. The left and right margins of the element in the row are not merged. Similarly, the margins of floating elements are not merged. You can specify a negative margin value, but be careful when using it.

 

 

The four margins are 10px:

H1 {Margin: 10px}

The top margin and bottom margin are 10 PX, and the left margin and right margin are 2% of the width of the parent element:

H1 {Margin: 10px 2%}

The top margin is 10px, the left margin and the right margin are 2% of the width of the parent element, and the bottom margin is-10px:

H1 {Margin: 10px 2%-10px}

The top margin is 10px, the right margin is 2% of the width of the parent element, and the bottom margin is-10px, and the left margin is set by the browser:

H1 {Margin: 10px 2%-10px auto}

 

CSS padding attributes

 

 

This short attribute sets all elementsPaddingOr set the width of the padding on each side. The padding value set on the non-replaceable element in the row does not affect the Row Height Calculation. Therefore, if an element has both the padding and background, it may be extended to other rows visually, it may overlap with other content. The background of the element extends through the padding. The negative margin value cannot be specified.

 

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.