Skip to content
Search

CSS:margin

lastmod 2022-12-20created 2022-12-201 edits

Negative margins

Negative margins do not touch the normal flow within the document (document flow). In other words, if you use a negative margin to move an element, all the elements that follow it move along with it.

They behave differently when floats are applied, so take extra care when using negative margins.

Summary of float and negative margin techniques

An element that comes after a floated element behaves as follows.

A normal element (one without float applied) that comes after a floated element does not recognize the floated element's existence and claims its own box area.

However, it does not intrude on the floated element's area.

Using this, you can apply a negative margin to a floated element: giving a negative margin in the direction opposite to the float pulls the content in.

See also

author Zer0 sitemap