Solve the problem of margin merging

Solve the problem of margin merging

1. Merge the margins of sibling elements

The effect is as follows: (the spacing between the two is 100px, not 150px)

2. Merge the outer margins of nested elements

For two nested elements, if there is no content in the parent element or the content is behind the child element and there is no top padding and border, the top margin of the parent element will be merged with the top margin of the child element, and the value will be the largest top margin, which will be used as the top margin of the parent element. Collapse occurs even if the parent element's top margin is 0. (collapse only occurs in the vertical direction)

Solution:

1. Define a 1-pixel top border for the parent element.

2. Define a 1-pixel top padding for the parent element.

3. Add overflow:hidden to the parent element;

Note that the first and second methods are not good and will increase the size of the box. The third method hides the overflowing content, which neither increases the size of the box nor affects the content.

Summarize

The above is what I introduced to you about solving the problem of margin merging. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

<<:  Faint: "Use web2.0 to create standard-compliant pages"

>>:  Detailed explanation of MySQL transaction isolation level and MVCC

Recommend

Example code for converting http to https using nginx

I am writing a small program recently. Because th...

How to output Chinese characters in Linux kernel

You can easily input Chinese and get Chinese outp...

VMware installation of Centos8 system tutorial diagram (Chinese graphical mode)

Table of contents 1. Software and system image 2....

Detailed explanation of monitoring NVIDIA GPU usage under Linux

When using TensorFlow for deep learning, insuffic...

Linux Disk Quota Management Graphical Example

Disk quota is the storage limit of a specified di...

MySQL 8.0.23 installation and configuration method graphic tutorial under win10

This article shares the installation and configur...

VMware Workstation virtual machine installation operation method

Virtual machines are very convenient testing soft...

Nginx configures the same domain name to support both http and https access

Nginx is configured with the same domain name, wh...

VMware12 installs Ubuntu19.04 desktop version (installation tutorial)

1. Experimental description In the virtual machin...

The difference between datatime and timestamp in MySQL

There are three date types in MySQL: date(year-mo...

MySQL configuration master-slave server (one master and multiple slaves)

Table of contents Ideas Host Configuration Modify...

Web page creation basic declaration document type description (DTD

Using CSS layout to create web pages that comply w...

How to handle forgotten passwords in Windows Server 2008 R2

What to do if you forget Windows Server 2008R2 So...

Let IE6, IE7, IE8 support CSS3 rounded corners and shadow styles

I want to make a page using CSS3 rounded corners ...