Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the outer margin in CSS

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about how CSS implements outer margins. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The gap that lingers around the element border is the outer margin. Configuring the outer margin can create an extra "blank" outside the element.

The easiest way to set the outer margin of the equipment is to use the margin property, which holds any unit of length, percentage, or even negative value.

CSS margin attribute

The easiest way to set the outer margin is to use the margin property.

The margin attribute suffers from any length unit, which can be pixels, inches, millimeters, or em.

Margin can set the equipment to auto. A more common practice is to set the equipment length value for the outer margin. The following name is configured with a space of 1 to 4 inches wide on each side of the H2 element:

H2 {margin: 0.25in;}

The following example defines different outer margins for the four edge divisions of the H2 element, using px units of length:

H2 {margin: 10px 0px 15px 5px;}

As with the inner margin setting equipment, the trajectory of these values is twisted clockwise around the element starting from the top and outer margin (top):

Margin: top right bottom left

In addition, you can set a percentage value for margin:

P {margin: 10%;}

The percentage is calculated relative to the width of the parent element. In the above example, the outer margin configured for the p element is 10% of the width of its parent element.

The default value for margin is 0, so if you declare a value for margin, there will be no margin. However, in reality, the hunting device has also provided a predetermined pattern for many elements, and the outer margin is no exception. For example, in a pro-CSS reader, the outer margin can be ripe into a "blank line" above and below each paragraph element. Therefore, if you declare an outer margin for the p element, the browser will generally apply an outer margin itself. As long as you make a special statement, it will cover up the default style.

Thank you for reading! This is the end of the article on "how to achieve the margin in CSS". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report