3 ms·
What I think we're starting to need is a separation between CSS for visual styling (font-size, border-radius, background-color, etc.) and CSS for layout (float,
by crazygringo 14y ago
What I think we're starting to need is a separation between CSS for visual styling (font-size, border-radius, background-color, etc.) and CSS for layout (float, margin-left, etc.).
The first can only be done by CSS in the browser. But the second can be accomplished via CSS, or by JavaScript.
As the web evolves, CSS for layout is increasingly not keeping pace. But it's not unreasonable to think that we could do away with it altogether.
Is there anything preventing someone from creating totally new layout models, based on new formats, that are parsed in JavaScript, and essentially turn everything into div's with position:absolute? And get recalculated upon window resize etc.?
This would completely free us from existing layout limitations of CSS, to do the exact kind of things like element queries, or whatever else we might think of.
I'm just not really sure what the performance implications would be like.
- ux-app 14y agoI agree with you 100% about the need to separate styling from layout. CSS for layout just plain sucks. Layouts that should be simple turn out to require hack upon hack to achieve. In regard to your layout in JS question. There is an excellent port of the Cassowary constraint solver in JS [1]. It allows you to specify complex relationships between containers along with weights, which allow you to specify layouts in a sane manner. Performance is very good, especially since it takes advantage of web workers where available. What I hate most about layout in CSS is that it takes something that should be brain-dead simple and turns it into something that requires memorization of edge cases and browser hacks with some added voodoo magic. It's such a waste of brain cycles. To top it all off constraint based solvers have been around for over 20 years... and yet in 2013 we're still dealing with this mess. [1] https://github.com/slightlyoff/cassowary-js-refactor https://github.com/slightlyoff/cassowary-js-refactor
- ihodes 14y agoThough obvious, FWIW: correct link to [1] https://github.com/slightlyoff/cassowary-js-refactor https://github.com/slightlyoff/cassowary-js-refactor
- ianstormtaylor 14y agoVery cool repo and articles that he links to. Lots of the layout constraints (not type-size, colors, etc.) should be solved when Flexbox support lands in the other major browsers. For example a 20% wide container, that gets no wider than 800px and no skinnier than 200px can be solved with Flexbox pretty easily. Not having adequate Flexbox support after it being discussed for soooo long is my other big problem with CSS.
- ux-app 14y agoflexbox is great, but it only solves a narrow set of layout issues. There's so much more that a constraint based system brings to the table. A layout system should make it extremely simple to anchor edges between arbitrary containers regardless of their position in the DOM. While we're at it lets scrap the DOM too. It's really painful to see how much it is being contorted to suit the application paradigm.
- talmand 14y agoYour complaint has more to do with how browsers implement CSS, not CSS itself.
- harlanlewis 14y agoIf you use javascript for layout, you're gonna have a bad time. But you're totally right about separating layout from structure. GridSet (http://gridsetapp.com http://gridsetapp.com) does some pretty amazing things. While it doesn't require you use a CSS preprocessor, you should check out the .scss it generates for a look into how they use preprocessor functions in a way that's much more similar to programming than CSS property-value lists. You should also check out Chris Eppstein's deck on his approach to structuring projects with separated concerns (https://speakerdeck.com/chriseppstein/help-my-stylesheets-are-a-mess https://speakerdeck.com/chriseppstein/help-my-stylesheets-ar...), and Jonathan Snook's SMACSS (http://smacss.com http://smacss.com).
- ux-app 14y ago> If you use javascript for layout, you're gonna have a bad time. I don't think this is necessarily true across the board. If you're creating just another brochure site then CSS does a good job of document layout and it's true that usign JS for layout is unnecessary and counter productive. If, on the other hand, you're creating complex layouts that mimic desktop applications (complex components, nested panels etc), then JS for layout is the only sane option.
- harlanlewis 14y agoThis is difficult to discuss in abstracts. "Javascript for layout" is much too vague, because of course everything is using a mishmash of javascript states, CSS media queries, and JSON content. I think what you're referring to is using javascript to build flexible layouts that afford a significant matrix of collisions between elements (w/ variable dimensions) by programmatically evaluating, resizing, moving, etc. For example, desktop Chrome's tabs: shrinking them as they increase in number, adjusting their position to keep the close button under the mouse, etc. But I'm having a hard time thinking of such beasts on the web, where such complications can't (or shouldn't) be limited by design. Share some examples?
- ux-app 14y agoThe types of layouts I was referring to are ones like: http://layout.jquery-dev.net/demos/complex.html http://layout.jquery-dev.net/demos/complex.html http://developer.yahoo.com/yui/examples/layout/adv_layout_source.html http://developer.yahoo.com/yui/examples/layout/adv_layout_so... https://gomockingbird.com/mockingbird/# https://gomockingbird.com/mockingbird/# http://docs.sencha.com/ext-js/4-2/extjs-build/examples/build/KitchenSink/ext-theme-neptune/#layout-accordion http://docs.sencha.com/ext-js/4-2/extjs-build/examples/build... These layouts all use a combination of CSS for layout (floats, margin, padding etc) as well as absolutely positioned elements that are controlled using some variety of layout manager. Where this becomes especially useful is for collapsible, resizable, movable panels and windows. A testament to the way in which CSS is lacking is evidenced through the hundreds of multi-thousand word blog posts that were devoted over the years to discussing how to achieve multi-column equal height flexible layouts [1]. This is something that should be trivial, instead hundreds of man years have been wasted trying to get boxes to line up nicely. CSS3 flexbox solves some of these issues, however there is still no way in which to arbitrarily constrain or anchor any container to any other container which ultimately limits its usefulness. [1] http://alistapart.com/article/multicolumnlayouts http://alistapart.com/article/multicolumnlayouts