How to use negative margins of floating elements in css
This article mainly introduces how to use the negative margins of floating elements in css. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
Float element
The effect of negative margins on float elements is also in accordance with the above, but it has its particularity, so it is very clear if we look at an example.
Negative margin of floating element
.float {overflow:hidden;width:280px;border:dashed 1px orange;}. Float .item {width:100px;height:100px;float:left;}. Float. Item:nth-child (1) {background:red;}. Float. Item:nth-child (2) {background:grey;}. Float. Item:nth-child (3) {background:blue;}
In a div with a width of 280px, the child elements of three float:left on the right, with a width of 100px, are moved to the next line because the last one does not fall.
We made a few changes to the code
.float {overflow:hidden;width:280px;border:dashed 1px orange;}. Float .item {width:100px;height:100px;float:left;}. Float. Item:nth-child (1) {background:red;}. Float. Item:nth-child (2) {background:grey;}. Float. Item:nth-child (3) {background:blue;margin-left:-20px;}
The third element adds the negative margin of-20px
At this time, it is found that the third element has been moved up and the second element, 20px, has been overwritten. The classic multi-column layout uses this principle.
The above is all the content of the article "how css uses negative margins of floating elements". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!