Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to overlay the outer margin in CSS

Shulou Source: shulou.com Published: 2022-05-31 13:11:02 11月15日 Update

This article mainly explains "how to overlay margins in CSS". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to overlay margins in CSS.

The code is as follows:

P {color: black; background: # ccc; margin-top: 50px; margin-bottom: 30px; height: 50px; border: 1px solid red;}

The lower margin of the first paragraph is adjacent to the upper margin of the second paragraph. You might think that the outer margin between them is 80px, but the actual spacing is 50px. When upper and lower margins like this meet, they overlap until one margin touches the border of another element. Therefore, here, the wider upper margin of the second paragraph will encounter the border of the first paragraph. In other words, the wider outer margin determines how far the two elements end up apart. This process is the outer margin superposition.

Thank you for your reading, the above is the content of "how to overlay margins in CSS". After the study of this article, I believe you have a deeper understanding of how to stack margins in CSS, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Superposition learning elements content that is borders two paragraphs up and down two between that is code reality ideas situations articles more knowledge points. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno Shulou Technology vpn MySQL