Live data from Hacker News

The Rules of Margin Collapse

joshwcomeau.com

31–35 of 35 posts

Re: The Rules of Margin Collapse

#32
post #10

Earlier quoted context omitted.

The behavior is very obvious if you use them for text. (I have had a few cases of naively stating my margins, the browser exactly displaying what I meant, instead of what I thought I have said, and needing to understand why it worked.) Just don't use margins for layout, I guess.

It actually makes sense for laying out UI elements. Unfortunately there is no horizontal collapse.

Just in case, in my Sciter horizontal margins do collapse in horizontal flows:

   container {
     flow: horizontal; /* single row */
   }

   container > child {
     margin:1em; /* will collapse */
   }
See: https://docs.sciter.com/docs/CSS/flows-and-flexes#flowhorizo...

Re: The Rules of Margin Collapse

#33

CSS is a testament to over-engineering.

You should try actually implementing packing, layout and size allocation algorithms sometime, if you have not. We have our own Canvas (aka scene graph) object inside Ardour and attempting to implement all of the above there showed how delightful most of CSS is, and how necessary.

Ardour[1] is Digital Audio Workstation software with a GPLv2 licence. Surprised I've never heard of it before. [1] https://ardour.org

Re: The Rules of Margin Collapse

#35

Earlier quoted context omitted.

I put everything in tables.

I just space everything out with  

There's someone on HN with a blog where everything is split into Spans that then have widths set by JavaScript to precisely lay everything out with pixel precision.

I was both impressed and appalled to see it.

Post reply on HN