Home > Web Front-end > HTML Tutorial > css details review notes--padding, borders and margins_html/css_WEB-ITnose

css details review notes--padding, borders and margins_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:46:58
Original
1820 people have browsed it

The padding, border, and margin properties of an element affect how the entire document is laid out, and more importantly, they can heavily affect the appearance of a given element.

Height and Width

These two attributes cannot be applied to inline non-replaced elements, whose height and width are determined by the content of the link, not by the author. Elements in normal flow rarely have a set height.

Margins and padding

If the element has a background, it will affect the use of padding and margins, because the background will extend into the padding, But it won't extend to the margins. The padding and margins specified for an element affect when the element's background ends.

Add 10 pixels of margin to each side of the content area, margin: 10px, similar to HTML's hspace and vspace, set an extra space around the image. Margin follows the following pattern:

margin: top right bottom left. The values ​​rotate clockwise around the element from top to bottom. If you want to get the effect you want, you have to order the values ​​correctly. When one of the values ​​is defaulted, the following rules will be followed:

1) If the value of the left margin is missing, the value of the right margin will be used.

2) If the value of the bottom margin is missing, the value of the top margin is used.

3) If the value of the right margin is missing, the value of the top margin is used.

In other words, if you specify 3 values ​​for margin, the 4th value will be copied from the 2nd one. If two values ​​are given, the 4th value will be copied from the 2nd value, and the 3rd value will be copied from the 1st value.

Single-sided margin attribute , for margin:auto auto auto 3em; equivalent to margin-left:3em; you can use a single margin-top, margin-right, margin-bottom and margin-left single setting margin.

The rules of "negative margins and merged margins" were discussed in the previous section: the margins of vertically adjacent block-level elements will be merged in normal flow. But when margins are applied to inline non-replaced elements, they have no effect on line height. Since margins are actually transparent, this declaration has no visual effect, since margins on inline non-replaced elements do not change an element's line height.

But note that there is an extra space between the end of the word before the inline non-replaced element and the border of the inline element's background. If you like, you can add this extra space to both ends of the inline element:

<p style="font-size:12px;line-height:14px;"> This is text<em>some of which emphasized</em>,plus other text<br>which id <strong style ="margin:25px;background:silver">strongly emphasized</strong>and which is<br>larger than the surrounding text. </p>
Copy after login

The effect is as follows:

If the inline element is not Things get more interesting by replacing the element with negative margins. The top and bottom margins of the element are not affected, nor is the line height, but the left and right ends of the element may overlap other content.

Replaced elements are different: the margins set for the replaced element do affect the line height, possibly making it increase or decrease depending on the value of the top and bottom margins. The left and right margins of an inline replacement element have the same effect as the left and right margins of the replacing element.

Border

Every border has 3 aspects: its width or thickness, its style or appearance, and its color. The default style of the border is none, and the border may not be visible. The default border color is the foreground color of the element itself, if no color is declared for the border it will be the same as the element text color.

Border style

If a border has no style, it will have no width, but in some cases you may want to create an invisible one frame. This introduces the border color transparent, which is used to create invisible borders with width. This transparent border acts as padding, so the element's background extends into the border area (assuming there is a visible background).

Percent value and padding

You can set a percentage value for the padding of an element. As with outer margins, percentage values ​​are calculated relative to the width of their parent element, so if the width of the parent element changes, they will change.

Note that the top and bottom padding are consistent with the left and right padding; that is, the top and bottom padding will be calculated relative to the width of the parent element, not relative to the height.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template