Back to all features
Open for signals CSS

margin-trim

The margin-trim CSS property removes the margins of child elements when they meet the edges of the container.

Community use cases (1)

What I want to do with this feature

There is many times where the margins at the top and bottom of the first and last element in some box are annoying and I find myself adding both margin-trim, as well as some workaround. Really hope margin-trim gets here soon, so I can remove those workarounds from my code.
I'm also more than mildly annoyed by the fact that the margin collapsing quirk has to exist, which could've been fixed, had margin-trim been a thing 25 years ago. So this property has a special place in my heart :)

What I'm having to do in the meantime

::first-child { margin-block-start: 0; }
::last-child { margin-block-end: 0; }