Live data from Hacker News

Should CSS be constraints?

pavpanchekha.com

41–46 of 46 posts

Re: Should CSS be constraints?

#41
post #23

Earlier quoted context omitted.

Layout can only expand/overflow to the right and down, not up or left. Although not fundamental, this has been a standard and useful design limitation in almost all software from the start: infinite drawing canvases are the only counterexample that immediately occurs to me. (“Pull to refresh” is almost another exception.) I’ve seen sites that centred in a way that caused balanced overflow while assuming a wider viewp…

> The result was a completely unusable site: the middle half was in-viewport (good), the right quarter was accessible by scrolling (poor), but the left quarter could not be accessed at all (abject failure). This is the limitation that browsers/css impose for a rather arbutrary reason [1] There's nothing preventing the browser from scrolling in any direction. [1] It's not arbitrary, of course. But almost all these qui…

Author here. You're right that a lot of CSS's edge cases and implicit rules stem from other choices and implicit rules that maybe need to be reconsidered. But take this logic a step further. The way text with mixed font sizes is laid out is kinda weird—should we just get rid of that? Mixed Chinese-Latin text is weird (search "idiographic baseline"); should we get rid of that? In fact, variable-size characters are weird, maybe just stick to all-Chinese? I'm joking, of course, but my point isn't that a simpler system is inconceivable, just that it would be inconvenient.

Re: Should CSS be constraints?

#42
post #3

Nice margin notes trick: float: right; margin-right: -12em;

Author here—it is from Tufte CSS. I have a blog post [1] about how floats work. It is a nice example of there being unintuitive and also more-intuitive ways to achieve things in CSS. These days I believe CSS Anchor Positioning provides a simpler way to do this, but I haven't used it yet.

[1]: https://pavpanchekha.com/blog/css-floats.html

Re: Should CSS be constraints?

#43

Apple's native SwiftUI framework and Google's Jetpack Compose framework stumbled upon basically the same layout system, "Constraints down, sizes up": 1. Proposal: The parent component proposes a size/constraints to the child 2. Measurement: The child component picks its own size based on those constraints 3. Placement: The parent component then positions the child in its coordinate space It's all done in a single pas…

That pretty much is how CSS works! At the most basic level, Flow level is about widths down, heights up. But this basic model doesn't let you do a lot of things some people want to do, like distributing left-over space in a container equally among children (imagine a table). So then CSS added more stuff, like Flex-box, which also fundamentally works like this though adds a second pass.

Re: Should CSS be constraints?

#44
post #7

> But with constraint-based systems, the layout might be literally under- or over-determined, in the sense that there might be more than one, or less than one, layouts that satisfy your rules. This is under the "what's wrong" section but it doesn't actually say what's wrong. Obviously if over-specified, the extra constraints can't be followed which wouldn't be intuitive (and... css does this constantly, so it doesn't…

Author here. The problem isn't the technical challenge of writing a constraint solver. It's making sure that the resulting layout looks good, despite contradictory guidance from the designer. Yes, a constraint solver can figure out which constraints it's violating. And for under-specification, it can produce a layout that satisfies the constraints. But the layout the constraint-solver chooses might be really bad—if a…

fwiw:

I do feel like I can speak on this some authority.

predictability is again suffers.

And recall that everything in parameterized.

Re: Should CSS be constraints?

#45
post #34
post #29

Grid Style Sheets / GSS was an implementation of this idea. https://gss.github.io/guides/ccss I saw was because I do not think anyone has used or maintained it since the company behind went belly up. But the code is still out there as open source, probably can be learned from. Disclaimer: I used to contract for them, but in other areas.

Hello Jon! This is Yarik. Cool to see you doing all this machine learning work these days.

Hi Yarik! Nice to hear from you again. Hope all is well :)

Re: Should CSS be constraints?

#46
post #35
post #29

Grid Style Sheets / GSS was an implementation of this idea. https://gss.github.io/guides/ccss I saw was because I do not think anyone has used or maintained it since the company behind went belly up. But the code is still out there as open source, probably can be learned from. Disclaimer: I used to contract for them, but in other areas.

If I am to provide a summary of why layout shouldnt be linear constraints, is that it can't faithfully represent content overflowing onto multiple lines. I.e. it's inherently one dimensional. I.e. you can't really have a layout that adaprts to the screen size without creating a lot of separate breakpoints. This is a big limitation, that for example flexbox doesnt have. When I left Grid i immediately went and reproduc…

Good point about overflow. Did you ever do any write-ups about your flexbox experiments, or constraints for layout more generally?
Post reply on HN