This is actually a really neat technique. I've done full-bleed layouts before grid was around, but it required messing around with negative margins, which is fragile and hard to get right.
Since the element you're trying to apply the full-bleed to lives in a container that has a max-width, wouldn't you need to play with negative margins or absolute positioning to accomplish this with only margins?
That’s left-aligned (margin-left: 0; margin-right: 0) rather than centre-aligned (margin-left: auto; margin-right: auto), but it gets the point across. Headings, paragraphs, list items, &c. all get their widths constrained (deliberately to different points, in my case, which wouldn’t work if you were going centre-aligned), but figures can be full-bleed simply by not having that max-width (though in my case they still need negative side margins, but of known values).
For a sidebar alone, you don't need CSS grid (probably obvious). The point of this article, i.e. having something full-bleed, is implemented by adding a specific class to the element. Which means you would always have a DOM similar to
My point is that now, with a new block element in the hierarchy, it would fill the maximum width anyway. It is only because of being inside a CSS grid that you now have to work around the grid positioning which means adding more CSS attributes.
The exception would be if you would want the full bleed element directly under the sidebar (in terms of z-index). Here CSS grid is useful, but this is probably a special case anyway.
Great article. While CSS grid is very powerful, maybe I'm not seeing the full picture in the examples: aren't the examples possible with just p { margin: 0 auto; max-width: 65ch } ? What does grid bring here?
I think part of it is that there are probably lots of additional items that you want to constrain to the main column, so your CSS would end up looking more like:
#content p, h1, h2, h3, nav { .. }
Kind of a pain to manually specify each element that you want to constrain, when it's most of them. This approach allows you to instead target the items that you don't want to constrain.
Additionally, as a more specific issue, the static-site generator that I use renders markdown such that images are inside a paragraph, so your approach wouldn't work at all for me.
Edit: As an aside, that's a super fun site! Lots of neat little UI easter eggs.
It's a neat demo of CSS Grid, for sure, but the above would be my much preferred way of doing this kind of layout. Maybe if there were a need for elements (quotes, callouts, etc.) in the side columns alongside the content, then it makes more sense to use Grid.
I left out some assumptions for brevity, but my presumption was that everything inside of the container (like p tags) would be display: block, so it would try to fill the max-width of 65ch with blank space anyway.
i think your version will break a bunch of common uses of `margin-{left,right}`; e.g. indenting like
blockquote {
margin-left: 15px;
/* ... */
}
won't work properly (it'll go all the way to the left). i haven't checked, but i think that in the grid version, you'd get an indent as expected.
and i think that's the grid version's main advantage – it doesn't "use up" `margin` and `max-width`, so you're free to use them to style stuff that appears in the body. feels a bit more composable, though at the cost of also feeling massively overcomplicated :/
ch is a fontsize relative unit and this solution wouldn't provide the same results for any element that has another text sizing and is not wrapped within a p tag.
and if you apply these rules to the whole content wrapper, you loose the ability to have some children selectively fill the viewport.
Did anyone else get weird screen flickering[0] from the animated stars used in a few places on this site? The dev-tools show the stars are <span> elements being added/removed dynamically. The animation is cutesy, but the flickering is annoying.
What I meant is that there is no way to tell certain children to disregard the constraints of a container; if a parent is 800px wide, there isn't a way to say "keep this child in-flow, but fill the viewport".
The alternative you propose is problematic for a couple reasons:
- I don't like "reaching in" to child elements. Especially in a component-focused architecture, it's a quick way to make a mess. My solution DOES reach in to apply a grid column, but that property only makes sense within the context of a grid, so it doesn't seem as problematic to me.
- the `ch` unit doesn't work properly when applied individually to different elements; an `h1` with 65ch width is going to be much wider than a `p` with 65ch width. You need the width to be applied to the parent, so that it remains consistent
- It's likely that you already have a constrained container, if you're adapting this solution to a page that already exists. If so, your approach isn't really workable without a major overhaul.
I'd also just add, the nice thing about using Grid is that it's super extensible. If you want to add a sidebar, it's quick and straightforward.
I do see how op misread your intention, but would like to add that you did a very good job on addressing all these shortcomings and provide a neat solution with this tutorial - very good work!
It’s beyond me why CSS has to be so hard to understand. I have made several attempts and got it right, but it feels like I have to start at zero every time.
I believe, it’s because CSS is not a programming language, but we are trying to do programming with it. Like: if screen is mobile then render divs stacked. I don’t know
True - I'm lucky not to have to consider versions of IE prior to 11 on most projects I work on, and I can usually get things working there, although there's a flexbox thing that I always forget with IE11 that catches me out.
I stand by my comment if you don't have to do IE < 11 though.
The environment for CSS isn't nearly as "standard" as you might think. Even though WebKit and Blink are the majority engines on mobile there's tons of combinations of versions, screen sizes, and aspect ratios. Trivial layouts are easy but more complicated layouts can be very difficult to get working right, let alone looking right, across browsers/platforms.
The problems are often solvable but not necessarily easy. The difficulty is compounded by the heterogeneity of the Android space.
It's great the majority browser engines follow the CSS standards but a lot of problems aren't bounded by the accuracy of the implementation.
Without wanting to diminish what you're saying, which makes a lot of sense - I feel like we should be trying to avoid complex layouts on mobile - at least in the browser.
And you're right that screen sizes can mess stuff up, Firefox/chrome mobile view on devtools doesn't always tell the full story... Got something working there and it was broken on my actual phone.
I think it really has more to do with the fact that it was originally only designed with print flow in mind. Like laying out a magazine with columnar text.
When it was initially designed there was an expectation that structural layout would happen outside of it and then you'd flow your text and other inline/block objects within that.
Most everything since then has just been about trying to get css back to the structural flexibility people had in 1996 with tables, while still trying to keep the flow flexibility css brought (and then, as you say, adding on media-type flexibility). It's not a surprise this turned out ugly.
I think it's because of the combinatorics of it and it's compounded by the specificity system, the size of the vocabulary, and no built-in compiler.
The combinatorics are tough for our lizard brains to reason out. If you don't have a strict set of rules for your CSS then you end up with a mixture of element rules, class rules, and id rules, and the combinations of these can get hard to hold in your head. Having compound styles doesn't help at all because it's easy to not realize you're setting a style accidentally.
Then what happens when there's a collision? The specificity system is supposed to sort that out, but without learning the rules there's just no way to intuit them. When I'm struggling with getting something just right and some library CSS is overriding my local CSS it's always the specificity rules that are at fault.
The vocabulary size is enormous. It's unclear exactly how many properties there actually are, but the most authoritative answer I could find was 522. That's a crazy number. And yes, that treats `margin` and `margin-left` as two separate properties, but they're still in there. By comparison there are 53 reserved words in Java and only 33 in Javascript. It's possible for a mere mortal to memorize these.
And finally there's no built-in compiler. Yes, I know about Sass, but that's not much more than a macro system; a useful macro system, but still just a macro system. A lot of us use compilers as our grammar and vocabulary checkers. If I do mis-spell a word in Java the compiler usually errors out and I'm forced to fix it. But if you mis-spell a property in CSS it's happy to just ignore it and you spend several minutes trying to figure out why your change did nothing.
For Javascript I used https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... and fudged the numbers a bit. There are future reserved words, but I didn't iinclude them because there's no point in memorizing them. Now that I look in detail that list also doesn't include "true", "false", and "null".
For me I think CSS is hard to understand mostly because the underlying concepts are low level and designed to accommodate ALL POSSIBLE rendering scenarios, not just "I'm putting a website on this laptop or phone screen".
CSS is able to target print and all manner of other different scenarios and needs. It's inherently complicated because it's very flexible and accounts for all kinds of use cases.
The problem is you don't need all that power most of the time, but it's there. To understand CSS you have to understand a lot of underlying concepts about layout and web page structure. People feel like "Why do I have to remember all these arbitrary rules?!". I sympathize - and sure a fair few things are arbitrary and never changed due to not breaking existing code - but most of the rules are not arbitrary, they just serve a bigger world than what we might be dealing with as web devs.
In the end I prefer to think of CSS as a powerful programming language that gives me lots of _primitives_, not a framework with a bunch of out of the box behavior that matches my narrow needs. If you want those, they are out there of course.
But yeah. CSS is hard and it takes study, practice, and time to be good at it. I think half of the time we struggle with CSS it's because we expect that it is "easy" and that it should cooperate without us investing time in learning it. It's written in short lines that look like plain English. It should do what we expect all the time, right?
Only an old textual part of it, e.g. grids cannot page-breaks. It is far from "flexible" and just "out there if you want". May I ask, do you even media print? Because every time I have to do unusual un-mainstream thing in css, I can bet that it will not work and make a net profit.
I think CSS is "difficult to understand" because most people who do front-end don't want to spend a day learning it.
Ask some people who make the claim it's difficult: what is the box model, and what is selector specificity. I can almost guarantee they won't be able to answer those questions, because they haven't bothered to actually try to learn CSS. Their knowledge of CSS is built from a set of "how do I do X in CSS" searches and the resulting stylesheets are hobbled together messes.
If you learn the box model, if you learn the reasons behind selector specificity, and how cascading works, you'll really earn a true appreciation for CSS. It does not take long to learn, you just have to spend a day reading through the "boring" stuff.
I've wanted to actually! It's become almost a meme that CSS is hard and a badge of honor to be ignorant of it, but it's not that bad. I will concede that there are some annoying design decisions (like margin collapsing) but overall, I think it's a well-designed and evolving solution that has stood the test of time. That we've been able to so easily add things like flexbox and Grid to it in response to the changing needs of the web is kind of a testament of how well CSS modelled the problem of layout. Learning box-model and cascading will let one solve 90% of common CSS problems people encounter just from first principles.
> most people who do front-end don't want to spend a day learning it.
Can you link to some good resources? I've read "CSS The Definitive Guide" by Eric Meyer, "Eric Meyer on CSS" (also by Eric Meyer) and "CSS Zen Garden" and I still can't get CSS to do anything useful and always resort to table-based layouts because they work.
Many of the css options that make complex layouts more palatable have only been commonly supported more recently. (flex-box:2015 , grid:2017, newer units:2010)
I don't remember the specific editions, but it was a long time ago - long before flex-box and grid were around. Still, back then, people could work magic with CSS using floats and positioning and such, and I couldn't make any sense of it. Maybe it's time to pick up a more up-to-date book on CSS and try again with the modern timesavers.
I don't know if there is a single perfect resource out there, but the thing that helped me the most was understanding CSS as a shift from programming with an imperative mindset to a declarative mindset. Treat CSS as a medium for expressing 'what you want' instead of 'what to do.' My guiding principle is that "less is more" and if you find yourself writing a ton of super-specific and messy CSS, it's one of two scenarios: there's an easier way to do it, or you have a very picky project manager who wants things to be pixel-perfect to the mock-up. If it's the latter, you have my sympathies.
Focusing on the box model is important because it sets the right overall mindset for working with CSS layout. At the risk of being too patronizing, I would highly encourage everyone to at least read the MDN article on CSS basics[0] just to set a baseline for CSS terminology, the idea of the box model, and a few other things.
You should then read more detailed documentation [1] on the box model and start to get a feel for how it works in depth. Most pedestrian "spacing issues" should be solved at the level of adjusting margins and padding.
The other arm I mentioned was specificity, and this tends to be where a lot of folks get caught asking why their rules aren't applying and those sorts of issues. The documentation is fairly 'academic' but worth a read-through[2].
MDN overall is a great resource for a motivated learner, but unfortunately I don't have any 'CSS the right way' sorts of articles in my hat at the moment. Maybe others will post some.
You sound a lot like me. I'll use CSS for colors/fonts/theming/separation and then do layout with tables :) . None of the stuff I work on is really all that complicated, so "tables are slow" just doesn't come up because the pages aren't large at all so 5ms vs 50ms doesn't matter.
This really deserves to be echoed. Accessibility just isn’t taken seriously by web developers in general and it makes me so sad. If it’s mentioned at all most of the time it’s an afterthought and they try to shoehorn it in on existing code as an afterthought which just makes things worse.
I want to implore everyone on HN to not be one of those people
Browsers, and therefore things like screen readers, see table elements as collections of tabular data. Using these elements for layout or design will cause a confusing and useless interpretation for people using a screen reader or analogous tool.
> I think CSS is "difficult to understand" because most people who do front-end don't want to spend a day learning it.
Yeah, "html/css" is the object of our derision on HN as some sort of thing that's beneath us. As if someone who is an "html/css" designer isn't a real developer. Yet at the same time we complain that we have to learn it. That after pretending it was trivial all this time, we're annoyed that we can't just fake our way through it when the going gets tough.
But the other reason it's hard is that UI and clientdev is hard. There's this weird meme that UI is just bells and whistles and stakeholder pleasers instead of a human interface that demands a lot of forethought and expertise, and something that has to be functional and possibly even a joy for the user to use. You can see this when people here brag about being backend developers that never touch the client as if that's something to brag about.
I've been writing CSS for about 10 years at nearly every professional job I've had. I don't get 'stuck' often and generally feel competent, but I am far from an expert or a master. I think CSS is difficult to understand because there are so many ways to accomplish a task, and so many of those ways lead to (sometimes) unforeseeable consequences, and nearly all of the APIs (possibly with the exception of css grid) don't feel very coherent... in my experience. I think it is difficult to learn because there's no real apparent holistic design to really grok.
I tried mdgriffith's elm-ui on a personal project and it was a breath of fresh air. It felt like an utterly excellent abstraction and I hope someone ports it to Typescript/React/JSX some day.
it also doesn't help that sometimes you have to whack-a-mole different browser implementations of the spec, and particularly if you're working on a bit of a website somebody else owns you have to be very careful about specificity, what styles other teams may be using, etc.
Yeah I think working with CSS is like working with Databases. There are a lot of ways in databases to get the job done. At first glance it seems to work the way you want and even survives early testing or even deployment. It doesnt fall apart until much later when you are trying to build upon it, scale it, etc.. This causes many people to learn the wrong way to do something because they might not stick around until it falls apart. The next time they have to do something they remember the way they got it to work last time and do it again, never realizing they are leaving a trail of tears for future developers to clean up the mess with.
CSS is very much the same way. I can't tell you how many times I have seen CSS files that are a house of cards. One wrong element gets added into a markup and the whole thing crumbles. Unnecessary use of !important, wildcards, overly specific, not specific enough, inconsistent media queries, desktop-first layouts (as opposed to mobile-first, or often times a mixture of the two depending on the element), and so on. At first glance, the stakes for bad CSS also seem pretty low (which is not the case with databases or backend code). This further causes developers to just hack at it until it works or is "close enough". It instills bad habits that last years or even entire careers.
The comparison with databases is an interesting one. I have observed in both that really diving into exploiting the domain in a language-native way (e.g. CSS or SQL) can lead to extremely powerful solutions, but ones which don't integrate very neatly into a broader system. So you usually find people inventing patterns, or restricting themselves to subset -- choosing to skip some of the power in favour of maintainability. You can build an entire system in just SQL and little-to-no other programming languages, but should you?
Yes, this exactly. Spend no time trying to understand something and then claim that something is hard to understand. No, sir, throwing stuff at the wall and hoping some will stick is not a good way to learn.
Alas, this approach is becoming more and more prevalent with everything, not just CSS.
While I agree with the main thrust of this comment; I don't think I'll ever "earn a true appreciation for CSS". Even the most careful application of class naming guidelines eventually creeps into specificity battles, and you cannot predict exactly what a line of CSS will do until it's actually applied to an element.
However: it's unclear to me what a better solution would look like; and it's clear to me that nothing better would ever be so much better as to "beat" CSS.
Pardon me, but I've read tens of technical references, rationales and getting started's in my life, but not a single one was so ritualistic and/or useless for practicing as everything about css. The reason is...
Their knowledge of CSS is built from a set of "how do I do X in CSS" searches
Because "box model and selector specificity" is light years away from how to do X. If you want an analogy, you are suggesting to win a chess tournament by thoroughly learning chess rules and figures. But you can not. It is okay for chess, where you build up your expertise for years and decades, but not for a rapid application development. Css is a bike with no front wheel, one pedal and it only turns left, unless you know that sit-backwards hack. There are better (more reason-enabling at least) layout systems out there, but cool web guys are digging in their heels on that "css" thing. And that would be okay, iff they made that damn bike at least complete, at least once in its lifetime.
Make all labels of the same, non-fixed width, for these forms to look more aligned under different label localisations. Without recomposing layout elements. In constraint-based layout, it is a.w = b.w = c.w (priority:low). In gtk, you add (a,b,c) into the same SizeGroup. In css I'm doing it the wrong way, these requirements are strange, I should rethink my model, take a different/better approach, maybe it is okay for them to not be aligned, because awesome css at least solves a huge load of problems and the internet rests on it, bla-bla-blah.
That even may have an almost-css-only solution, but whatever it is, it will be yet another "recipe" with a pile of crutches as ingredients. Which is likely not compatible with rendering loops or a structure of a half of popular js/css frameworks.
CSS is a top-down language, not a constraint language. It is not surprising that you cannot construct things in the same way as you would in a constraint-based layout system.
I am sure I could discover an equal "simple" example that is easy in CSS but difficult/impossible in GTK.
That you cannot use a hammer in the same way as a crowbar, even though they are both blunt instruments, is not a condemnation of the hammer. So yes, you do need to evaluate what the right tool for the job is - like JS to do a quick width-match on the labels' natural widths - after the CSS did most of the rest. That is not "bla-bla-blah," that's just knowing the limits of your tools.
The frustration seems to be the impression that CSS should be able to solve any conceivable layout desire on the web, which isn't its charge: CSS is first and foremost made to style web documents, which by-and-large don't fit as easily into the constraint-based-layout box as a traditional desktop app would. Since this kind of desire often crops up in desktop-like SPAs, where JS use is endemic already, it's not wrong to use a little bit more JS to nudge the visual experience a little closer to what you'd see on a desktop app.
I guess my takeaway is, CSS doesn't promise the world, so if you come in expecting that, you'll walk away disappointed. Luckily there are many tools in the web dev toolkit to achieve your engineering desires, and it's not verboten to use them (aside from a philosophical desire to avoid JS, but if the biggest problem for your page when JS is disabled is that the labels are slightly different sizes, I think you're doing a great job already).
You just switched from blaming me for not knowing css to blaming me for not using the right tool, as if I had a clear way to do that. It is nothing new and was propheted in bla-blah paragraph. But if you ever tried to size-match in JS, you know that it is not a trivial task. First, an element must be temporarily placed into document.body for all styles to apply correctly. Second, it must repeat all of the hierarchy it was in, which requires to break/duplicate a component encapsulation in your code. Third, in a narrow-width situation you simply cannot guess what surrounding containers would do to the effective width/height based on an intrinsic geometry. Not even speaking of cpu/battery issues, these three alone make it possible only in theory. And no, there is no library for that to "just work" in your project.
I am sure I could discover an equal "simple" example that is easy in CSS but difficult/impossible in GTK.
I doubt it, really. I mean, you could find something for base gtk (which is already out of reach compared to css in ui geometry, because it was done for it), or for the fact that gtk is not a networking engine, but it is just a bunch of predefined containers, calculation phases and signals in C. It is easily extensible in a native way and hides no knowledge about how everything looks or works. Gtk is an example of how you expose distinct particles, pre-implement few useful combinations, and then users build a universe with them. Css is an example of ritualistic black box that hides almost everything about its geometry and requires a non-trivial effort for really basic things. E.g. in css, you have to struggle with dumbest things like a one-pixel vertical scroll in a single-line input. My complaint is not "css is not gtk-like", it is "css is incomplete and unreasoned AF in its own model".
It was my bla-blah, so please read it as etc-etc, and if you feel offended by that and by my tone, I apologize. But it would be fair if you also excused my huge disappointment after following these exact ideas, spending days and finding out that they do not work or are completely non-viable in vivo. If any css loving guy implemented the puzzle above (and a half of other common issues) as a library that could be simply added to a job-grade project, they are welcome to share it (or sell, such an easy $$$). I've been in these discussions and done what was suggested, that's why I listed all these reasons word by word, before anyone had a chance to repeat them, and that's where my criticism comes from. I just cannot sit here and silently watch how they praise a thing that is not remotely as good as is claimed. How many man-centuries have to be spent until we all admit the undeniable?
While I think this is definitely a useful foundation, things get a lot more complicated quickly once you jump into a large site's stylesheet(s).
Why isn't this element the size I specified? Or why is there a tiny amount of scroll overflow here when I specify overflow-x hidden? What does vertical-align do and how does it work when inline and inline-block boxes are in an inline flow? etc. etc.
So I would add that the next frontier after learning the proposed foundations is learning how the browser actually determines box sizes and layout, and I think this is difficult to understand, mainly because it jumps straight into the spec, or worse, your browser's layout engine specifics.
https://www.w3.org/TR/css-sizing-3/#auto-box-sizes for instance is a nontrivial subsystem that a CSS dev will easily run into when nesting flex containers, and I think the standard box model of yore wasn't really written to help grok these concepts.
Edit: one particularly hairy explanation from the spec I recently ran into while trying to deepen my understanding of the box model:
"Except for table boxes, which are described in a later chapter, and replaced elements, a block-level box is also a block container box. A block container box either contains only block-level boxes or establishes an inline formatting context and thus contains only inline-level boxes. Not all block container boxes are block-level boxes: non-replaced inline blocks and non-replaced table cells are block containers but not block-level boxes. Block-level boxes that are also block containers are called block boxes."
Not saying this is relevant for the average use case, but I believe even something like the box model is a day-to-learn-lifetime-to-master kind of thing.
> I think CSS is "difficult to understand" because most people who do front-end don't want to spend a day learning it.
I couldn't disagree more. There are a ton of reasons CSS really is hard, even when one understands the box model etc.
E.g.:
1. Hugely non-modular. An element's behavior always depends, to some extent, on styles applied to other elements. Systems full of entangled global state are inherently complex, separate from any other concern.
2. Highly magical. E.g. if you want to control how elements stack with z-index, you need to also know that z-index is ignored for elements that aren't positioned, which in turn means you need to set up your margins differently because positions disable margin collapsing. There's no one "model" to learn; it's a big morass of interconnected rules and edge cases.
3. Extremely fragile. Layout changes that a human user might consider minor often can't be done without significantly redesigning the page.
Of course, problems like these can all be mitigated to various extents. But that takes care and experience; it's not just a matter of reading some articles like you imply.
Where is the best place to learn CSS from a more foundational/complete perspective? I took freeCodeCamp's responsive web dev course but still find myself googling a lot of "how to do x in CSS"
This is me. My brain chucks it in the bitbucket as soon as the project over. 95% of my time is in firmware with the occasional web page/javascript to update and I google and It All Starts Making Sense, and then the project is over and I don't touch it again for 2 years :)
One reason it is hard is that the effect of CSS rules depends on their order. Imagine if in your JavaScript you write 5 functions, and depending on the order you write them in causes them to have a different effect.
I don't like selectively making some children full bleed within an otherwise constrained container. Use full bleed containers instead imo and don't mix the two
Not the original commenter, but you would just write the container as full bleed and constrain the elements with-in it. That way any elements not so constrained are by default full-bleed. I'm of mixed minds which I like better, generally I prefer less elements and less nesting when possible, but there are almost always going to be wrapping elements in any mildly complex site.
I’m using Bootstrap’s approach of a `.container-fluid` class for a full-bleed container, and a `.container` class for the standard centered and fixed width container.
I’m interested in applying CSS Grid as a progressive enhancement specifically targeting browsers supporting it, and keeping what I do today for browsers that don’t.
I really hated this era before flexbox and co. CSS used to be the least intuitive thing on the planet yet a lot of people claimed otherwise. We had to resort to silly tricks (remember overflow hidden?) in order to make up for the mess that CSS used to be. Again what really pissed me off isn't CSS inherent issues but the fact that many people claimed there was absolutely nothing wrong with it, a pattern I often see with many developers about this or that language. Obviously, there were some problems or we wouldn't be needing CSS grids or flexbox today.
I don't understand this.
You can appreciate something while still acknowledging its obvious flaws, nothing is perfect.
Seems like a bit of a strawman, people who couldn't think of a single issue with CSS. You are generally talking to beginners when you encounter anyone like that on any subject. Kind of like trying to draw too many conclusions from a Twitter argument you had with someone who is actually a 14yo (probably happens a lot more than we like to think).
Instead I think I could agree with people who could point out that it's all trade-offs, and there are some upsides to having fewer autolayout options in UI programming. For example, flexbox and cssgrids enables things you simply wouldn't have attempted before in CSS (you'd have gone with something less expressive, like media-query hard-coding). And any time you nest grids and/or flexboxes you get to rediscover the horrors of autolayout flexibility.
UI is hard and there is no "best". Though it's the emergence of mobile devices that forced the hand to more complex autolayout tools.
I've noticed that some people mistake 'the best extant X' with 'X has no problems.' For instance, 'Y is a problem with X' will often receive the response 'Nuh-uh, because extant Z also has problem Y but is worse than X in other respects.' Look for this particularly in conversations about smartphones.
> > iphones have poor battery life, I'd like a phone that keeps a charge for a full week at least.
> No you're wrong because android phones also have bad battery life.
I find it really frustrating when project runners refuse to acknowledge shortcomings. I'm not always expecting them to solve it, but I'd at least like an acknowledgement that the issue I'm facing is valid. Pretending it's just me or that the obviously worse alternative is okay gets annoying.
One example is ReasonML's async story:
Q: What's BuckleScript's async story?
A: If you're not interfacing with any library that uses promises, you can simply use callbacks. Everyone gets them and they're performant. If you need to bind to a JS library that uses promises, or communicate with such library, you can use BS's Js.Promise.
IMO that's a less than ideal response. I'd prefer a more honest response like:
A: Unfortunately, we do not offer an async/await equivalent currently. BuckleScript has a Js.Promise type for using Promises. We understand that this is not ideal, and are working on other options.
Look—it's okay that they don't have the feature. Nobody's perfect. But they shouldn't pretend that callbacks are an acceptable replacement because they're "performant".
This is my biggest bugbear (the general behaviour, not the specific example). I want to make good technical decisions, your library has made choices based on its principles and design goals, don't obscure the trade-offs you've been made -- this is just a (poor) growth hack in disguise.
I've seen so many people use technologies then regret it a year later because they realised what they actually wanted to achieve was at odds with the design goals of the technology.
In my experience, no matter how many improvements there have been, there are always things that you are trying to do that css doesn't support or make easy to do. Recently I've tried making tabs the same width but not justified horizontally, meaning all tabs should have the same width as the widest one. Something like this (1) but without hard coding the children count. In my mind, you would be able to set the widths to max-width of siblings. In general, I would love to have more signifiers that describe relations between elements.
Then what direction of relationship would have precedence, left to right? Right to left? If neither how precedence would be defined? Overall I don't want css to become any more complex, if you need an edge case such as that one JavaScript is a great tool for the job.
Yeah I have the same feeling. I was struggling for hours the other week to make two columns the same height, but the need for an overflow on one kept on killing everything.
Coming from a mechanical engineering background, I'm very used to being able to define spatial properties with respect to other elements in CAD, and it just seems lacking in CSS.
It's tough to know that something is bad when you don't know about anything better. I remember when I started doing Android development was when I really realized how terrible CSS was. And this was long before all the new constraint stuff in iOS and Android that still makes CSS look bad.
i suspect you might be mixing up people who talked about the spec and actual end users - at least can't seem to recall anyone ever saying css is good as it is, back in the days. The shortcomings where well known and anmoying to anyone having to work with them. But that might be true to my bubble only.
Just wanted to say that's an excellent tutorial. I almost never touch anything on the front end. My web dev skills are, at best, thoroughly out of date. But I could still follow and understand everything presented. If you're reading, thanks Josh. Great job.
I especially appreciate how the end solution was presented fairly early in the tutorial after the stage had been set. I find it helpful to see the code representing "where we're going" instead of holding out until the very end to arrive there.
Grid enables you to do this (and a lot more) in a way that works across all modern browsers without much code in a robust and consistent manner. If you still need to support IE or older Android it's useful to understand other approaches but if you want to deploy something today that works grid is an excellent approach.
I've been building front end stuff for about 25 years and grid is much more straightforward than any approach that's come before it. Tables were a hassle to change, floats were fragile across browsers, flex was (and still is) good, but grid is a step up from all of those.
Just as an FYI, I've run into browser compatibility issues when using grid. It's been a while since I worked on that project, so hopefully mobile / edge / safari / chrome / firefox are all on the same page now, but it wasn't great a year or two ago. Go here [1] and keep hitting more, there are unfortunately lots of things not working in Safari and partly in Firefox.
> Have you ever tried to read Wikipedia on a very large screen? It looks like this: [image] Those paragraphs are so wide! Wikipedia doesn't constrain the container width at all. This leads to lines that are hundreds of characters in length.
NOOOOO! Please, please, please, please stop second-guessing my choice of browser window width! I bought a nice 27" monitor, and maybe I just want to use the whole thing. Why is your opinion about the amount of space I should be able to use for text more important than mine? I honestly don't care what your research says about optimal character lengths. I deliberately stretched my browser window to be this wide. Please don't override me.
Two reasons. One, the designer of the site has a specific UX and UI in mind, and that is their decision. If you don't like it, you can hack it with local CSS or just use a different site.
Two, (I know you don't care, but for others reading) there are studies that show that for the vast majority of people, width constraints make it easier to read. So there is good reason to enforce those constraints in the design from a usability perspective, not just a design perspective.
Sorry you don't care about the research. When I'm building a site I absolutely DO care about the research, and what will make it work the best for the largest number of people.
Have you read the research? It doesn't really support the claims people make about it. A good starter thread (albeit it's hard to follow all the replies in the nested conversations): https://twitter.com/danluu/status/1115707741102727168
I've read quite a bit of it. It really depends on the claim. Speed is generally faster with longer lines, although it does seem like there is an upper limit. But comprehension and subjective judgement (yes, that last is hard to quantify) seem to be best between 40-60 characters (actually less than the commonly recommended 65 as seen in the original post here). Also, it's generally not line-length, but characters per line, that matters, and keeping the visual angle from changing as the user reads.
So it depends on what exactly is being measured, which is why I said the overall UX and not something more specific.
Even apart from that, I just see no point in constraining the widths forcefully. Just let the width adapt to the browser width, then each user can size it to his/her preferences and needs of the moment. Win-win for everyone.
I guess my rant should be more directed towards browsers. I remember Netscape allowing me to specify all sorts of stylistic preferences. Hell, I could easily make your web site's background be a brick wall if I wanted to. Most those things have kind of disappeared by now, and we're left with CSS hacks, "Disable CSS" and "Reader Mode". Oh and I guess we can set default fonts and colors too, but those just get over-ridden by 99% of sites. Would be nice if User-agents would return some more control back to the actual user.
Yah, I definitely miss the days of providing your own user style sheet without plugins or other addons. These days I don't hardly bother, although I will pop open the dev tools to "fix" something once in a while if it's really bad.
The people of number two can resize their browser window.
If I prefer full width lines I'm forced to the designers specific UX. That's quite ironic because the U in UX stands for user and my eXperience with such sites is horrible.
Worst of all are those that have code examples that go beyond the column width but don't wrap, so I have to scroll horizontally even though two thirds of the page are empty.
I like this idea, but how do you deal with pseudo bleed elements overlapping with sidebar content? For example many websites put navigation elements on the sidebar [1], or margin notes [2], [3]. I personally would love to see a css only solution for pseudo bleed with margin notes. The only solutions I've found so far use resize observer to absolutely position the margin notes using js or have hand coded positions and offsets.
A compromise might be to hide navigation elements or margin notes until you hover / click on an element, sort of like how Wikipedia enables page previews on internal links.
A quick note is that by using CSS grid, margins are not collapsed. For the example in the article, the heading and the paragraph are rows, so if they have top and bottom margins, they will be further apart than normally. This can break design sometimes
Slightly OT, but this page has the BEST alternative for a modal newsletter pop-up I’ve ever seen. I have a personal rule that I close the tab as soon as a modal asking for my email pops up. When the cute little figure on the left _asked_ for my consent to pop-up a modal, I had to click on it because it was so cute and respectful.
This is great design that I’m sure converts as well without cheapening your brand and accosting your users.
What information are you concerned about them harvesting that they won't have gotten just from the ad loading? I suppose time on site and stuff, but I'm not sure what bits of info you're trying to hide. Feels like a situation where you might as well enjoy the content.
The translucent gradient overlay this site has is truly obnoxious. What possesses people to do things like this? Headers that follow you when you scroll down the page are bad enough, but this is truly abominable. Don't fade out text I'm trying to read dammit!
Delete StandardLayout__GradientWrapper, it served no useful purpose, it only pisses people off.
I've thought blocking sticky header would remove it but no —
flying gradient. Besides how to support names like StandardLayout__GradientWrapper-sc-1x2euwc-2 doIIpB in annoyance list? They would change in a moment.
If your screen is too wide to read websites comfortably, why don't you resize your browser?
What is the point of buying a bigger monitor if you're still going to full-screen your browser to the point you can't read anymore? Isn't the point of bigger monitors to show more things at once?
These days we have many websites with giant empty spaces on the left and/or right, all in the name of making the text lines short enough (much shorter than I like them, but that's another rant). Making the browser window smaller often makes the text even smaller, instead of the useless empty spaces. Make some room for my other windows, please! We're not in the 90's anymore where monitors were only large enough for one window.
There's this trend of very wide and ultra wide monitors. I sincerely hope people don't use their browsers full-screen on 3440x1440 monitors.
Unless those empty spaces are supposed to be filled with ads that my ad blocker blocks for me. But that too is another rant.
> These days we have many websites with giant empty spaces on the left and/or right, all in the name of making the text lines short enough (much shorter than I like them, but that's another rant).
The other rant is here: [1].
Curious why do you hope people don't use their browsers full-screen? How does someone else's browsing preference affect you? Am I a lesser person if I want to use my browser full-screen on a 5120x2880 retina display?
It seems more and more every year, the user's preference gets sidelined in favor of the web site designer's preference. I never thought it would get to this, but as web sites get more and more opinionated about enforcing their particular stylistic choices, I'm more often than not feeling the need to disable CSS or go into Reader mode. I wish browser developers would provide better tools to override questionable site designs, rather than taking them away. At least I can still change the font size with the browsers (shhhh--don't give them any ideas).
I'm not trying to tell you what to do. But if YOU make your browser wider than YOU can comfortably read, why do you expect ME the developer to do something with CSS to deal with it?
If I choose to fullscreen my browser window, I'm not expecting the developer to do anything about it. In fact, I'm hoping he will not choose to go out of his way to try to do something about it (e.g. deliberately adding whitespace). Honoring the user's preference often means less code/CSS.
Another solution which I haven't seen anyone here mention yet is having multiple text columns, essentially splitting up your content into paragraphs that are laid out side-by-side, like you often see in newspapers and research papers.
This has its drawbacks and some people don't like it, but surely it's better than only using 20% of the width of a wide display.
I would like to see more websites at least include it as an option.
CSS Grid is horrendous to debug once it gets complex and you can’t rely on document flow any more, things can be placed anywhere which might seem big and clever but a few nested grids + the cascade and you’re quite frankly screwed. If you really must use CSS grid I say use it for the main layout and nothing else, then at least future you has a chance.
Also this is more complex than using negative margins ever was.
276 comments
[ 3.1 ms ] story [ 274 ms ] threadAs a matter of fact, that would require even less attributes to work compared to the method presented in the article.
This is not really CSS magic:
That’s left-aligned (margin-left: 0; margin-right: 0) rather than centre-aligned (margin-left: auto; margin-right: auto), but it gets the point across. Headings, paragraphs, list items, &c. all get their widths constrained (deliberately to different points, in my case, which wouldn’t work if you were going centre-aligned), but figures can be full-bleed simply by not having that max-width (though in my case they still need negative side margins, but of known values).
The exception would be if you would want the full bleed element directly under the sidebar (in terms of z-index). Here CSS grid is useful, but this is probably a special case anyway.
Additionally, as a more specific issue, the static-site generator that I use renders markdown such that images are inside a paragraph, so your approach wouldn't work at all for me.
Edit: As an aside, that's a super fun site! Lots of neat little UI easter eggs.
and i think that's the grid version's main advantage – it doesn't "use up" `margin` and `max-width`, so you're free to use them to style stuff that appears in the body. feels a bit more composable, though at the cost of also feeling massively overcomplicated :/
ch is a fontsize relative unit and this solution wouldn't provide the same results for any element that has another text sizing and is not wrapped within a p tag.
and if you apply these rules to the whole content wrapper, you loose the ability to have some children selectively fill the viewport.
FF 80.0.1 MacOS 10.14 (yeah it's old)
[0]https://vimeo.com/465078029
Yes it does. You can use
or soon Alternatively, you can also use And in SCSS (or similar) you can write (edit: Earlier versions of this comment mentioned :has instead of :is)What I meant is that there is no way to tell certain children to disregard the constraints of a container; if a parent is 800px wide, there isn't a way to say "keep this child in-flow, but fill the viewport".
The alternative you propose is problematic for a couple reasons:
- I don't like "reaching in" to child elements. Especially in a component-focused architecture, it's a quick way to make a mess. My solution DOES reach in to apply a grid column, but that property only makes sense within the context of a grid, so it doesn't seem as problematic to me.
- the `ch` unit doesn't work properly when applied individually to different elements; an `h1` with 65ch width is going to be much wider than a `p` with 65ch width. You need the width to be applied to the parent, so that it remains consistent
- It's likely that you already have a constrained container, if you're adapting this solution to a page that already exists. If so, your approach isn't really workable without a major overhaul.
I'd also just add, the nice thing about using Grid is that it's super extensible. If you want to add a sidebar, it's quick and straightforward.
I'm now off to learn more about this magical "ch" unit.
I believe, it’s because CSS is not a programming language, but we are trying to do programming with it. Like: if screen is mobile then render divs stacked. I don’t know
Also the "cascading" nature of CSS makes it hard to reason about.
Safari and IE are the big bugbears in my experience.
I stand by my comment if you don't have to do IE < 11 though.
The problems are often solvable but not necessarily easy. The difficulty is compounded by the heterogeneity of the Android space.
It's great the majority browser engines follow the CSS standards but a lot of problems aren't bounded by the accuracy of the implementation.
And you're right that screen sizes can mess stuff up, Firefox/chrome mobile view on devtools doesn't always tell the full story... Got something working there and it was broken on my actual phone.
When it was initially designed there was an expectation that structural layout would happen outside of it and then you'd flow your text and other inline/block objects within that.
Most everything since then has just been about trying to get css back to the structural flexibility people had in 1996 with tables, while still trying to keep the flow flexibility css brought (and then, as you say, adding on media-type flexibility). It's not a surprise this turned out ugly.
The combinatorics are tough for our lizard brains to reason out. If you don't have a strict set of rules for your CSS then you end up with a mixture of element rules, class rules, and id rules, and the combinations of these can get hard to hold in your head. Having compound styles doesn't help at all because it's easy to not realize you're setting a style accidentally.
Then what happens when there's a collision? The specificity system is supposed to sort that out, but without learning the rules there's just no way to intuit them. When I'm struggling with getting something just right and some library CSS is overriding my local CSS it's always the specificity rules that are at fault.
The vocabulary size is enormous. It's unclear exactly how many properties there actually are, but the most authoritative answer I could find was 522. That's a crazy number. And yes, that treats `margin` and `margin-left` as two separate properties, but they're still in there. By comparison there are 53 reserved words in Java and only 33 in Javascript. It's possible for a mere mortal to memorize these.
And finally there's no built-in compiler. Yes, I know about Sass, but that's not much more than a macro system; a useful macro system, but still just a macro system. A lot of us use compilers as our grammar and vocabulary checkers. If I do mis-spell a word in Java the compiler usually errors out and I'm forced to fix it. But if you mis-spell a property in CSS it's happy to just ignore it and you spend several minutes trying to figure out why your change did nothing.
Where did you find these numbers? I'm trying to find them but I can only find the Ecmascript and the number appears way higher
51 listed here https://docs.oracle.com/javase/specs/jls/se15/html/jls-3.htm... with a bunch of non keywords listed below, of which true false and null are also reserved
For Javascript I used https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... and fudged the numbers a bit. There are future reserved words, but I didn't iinclude them because there's no point in memorizing them. Now that I look in detail that list also doesn't include "true", "false", and "null".
CSS is able to target print and all manner of other different scenarios and needs. It's inherently complicated because it's very flexible and accounts for all kinds of use cases.
The problem is you don't need all that power most of the time, but it's there. To understand CSS you have to understand a lot of underlying concepts about layout and web page structure. People feel like "Why do I have to remember all these arbitrary rules?!". I sympathize - and sure a fair few things are arbitrary and never changed due to not breaking existing code - but most of the rules are not arbitrary, they just serve a bigger world than what we might be dealing with as web devs.
In the end I prefer to think of CSS as a powerful programming language that gives me lots of _primitives_, not a framework with a bunch of out of the box behavior that matches my narrow needs. If you want those, they are out there of course.
But yeah. CSS is hard and it takes study, practice, and time to be good at it. I think half of the time we struggle with CSS it's because we expect that it is "easy" and that it should cooperate without us investing time in learning it. It's written in short lines that look like plain English. It should do what we expect all the time, right?
Only an old textual part of it, e.g. grids cannot page-breaks. It is far from "flexible" and just "out there if you want". May I ask, do you even media print? Because every time I have to do unusual un-mainstream thing in css, I can bet that it will not work and make a net profit.
Ask some people who make the claim it's difficult: what is the box model, and what is selector specificity. I can almost guarantee they won't be able to answer those questions, because they haven't bothered to actually try to learn CSS. Their knowledge of CSS is built from a set of "how do I do X in CSS" searches and the resulting stylesheets are hobbled together messes.
If you learn the box model, if you learn the reasons behind selector specificity, and how cascading works, you'll really earn a true appreciation for CSS. It does not take long to learn, you just have to spend a day reading through the "boring" stuff.
Can you link to some good resources? I've read "CSS The Definitive Guide" by Eric Meyer, "Eric Meyer on CSS" (also by Eric Meyer) and "CSS Zen Garden" and I still can't get CSS to do anything useful and always resort to table-based layouts because they work.
Many of the css options that make complex layouts more palatable have only been commonly supported more recently. (flex-box:2015 , grid:2017, newer units:2010)
Focusing on the box model is important because it sets the right overall mindset for working with CSS layout. At the risk of being too patronizing, I would highly encourage everyone to at least read the MDN article on CSS basics[0] just to set a baseline for CSS terminology, the idea of the box model, and a few other things.
You should then read more detailed documentation [1] on the box model and start to get a feel for how it works in depth. Most pedestrian "spacing issues" should be solved at the level of adjusting margins and padding.
The other arm I mentioned was specificity, and this tends to be where a lot of folks get caught asking why their rules aren't applying and those sorts of issues. The documentation is fairly 'academic' but worth a read-through[2].
MDN overall is a great resource for a motivated learner, but unfortunately I don't have any 'CSS the right way' sorts of articles in my hat at the moment. Maybe others will post some.
[0]: https://developer.mozilla.org/en-US/docs/Learn/Getting_start...
[1]: https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_...
[2]: https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
https://css-tricks.com/snippets/css/complete-guide-grid/
I want to implore everyone on HN to not be one of those people
Andy Bell posted front-end challenges for a while, here's the archive: https://piccalil.li/category/front-end%20challenges%20club/
Codepen hosts challenges every week. They aren't always CSS focused but many of them are. https://codepen.io/challenges
Yeah, "html/css" is the object of our derision on HN as some sort of thing that's beneath us. As if someone who is an "html/css" designer isn't a real developer. Yet at the same time we complain that we have to learn it. That after pretending it was trivial all this time, we're annoyed that we can't just fake our way through it when the going gets tough.
But the other reason it's hard is that UI and clientdev is hard. There's this weird meme that UI is just bells and whistles and stakeholder pleasers instead of a human interface that demands a lot of forethought and expertise, and something that has to be functional and possibly even a joy for the user to use. You can see this when people here brag about being backend developers that never touch the client as if that's something to brag about.
I tried mdgriffith's elm-ui on a personal project and it was a breath of fresh air. It felt like an utterly excellent abstraction and I hope someone ports it to Typescript/React/JSX some day.
CSS is very much the same way. I can't tell you how many times I have seen CSS files that are a house of cards. One wrong element gets added into a markup and the whole thing crumbles. Unnecessary use of !important, wildcards, overly specific, not specific enough, inconsistent media queries, desktop-first layouts (as opposed to mobile-first, or often times a mixture of the two depending on the element), and so on. At first glance, the stakes for bad CSS also seem pretty low (which is not the case with databases or backend code). This further causes developers to just hack at it until it works or is "close enough". It instills bad habits that last years or even entire careers.
However: it's unclear to me what a better solution would look like; and it's clear to me that nothing better would ever be so much better as to "beat" CSS.
Their knowledge of CSS is built from a set of "how do I do X in CSS" searches
Because "box model and selector specificity" is light years away from how to do X. If you want an analogy, you are suggesting to win a chess tournament by thoroughly learning chess rules and figures. But you can not. It is okay for chess, where you build up your expertise for years and decades, but not for a rapid application development. Css is a bike with no front wheel, one pedal and it only turns left, unless you know that sit-backwards hack. There are better (more reason-enabling at least) layout systems out there, but cool web guys are digging in their heels on that "css" thing. And that would be okay, iff they made that damn bike at least complete, at least once in its lifetime.
Want a simple, trivial puzzle?
Make all labels of the same, non-fixed width, for these forms to look more aligned under different label localisations. Without recomposing layout elements. In constraint-based layout, it is a.w = b.w = c.w (priority:low). In gtk, you add (a,b,c) into the same SizeGroup. In css I'm doing it the wrong way, these requirements are strange, I should rethink my model, take a different/better approach, maybe it is okay for them to not be aligned, because awesome css at least solves a huge load of problems and the internet rests on it, bla-bla-blah.That even may have an almost-css-only solution, but whatever it is, it will be yet another "recipe" with a pile of crutches as ingredients. Which is likely not compatible with rendering loops or a structure of a half of popular js/css frameworks.
I am sure I could discover an equal "simple" example that is easy in CSS but difficult/impossible in GTK.
That you cannot use a hammer in the same way as a crowbar, even though they are both blunt instruments, is not a condemnation of the hammer. So yes, you do need to evaluate what the right tool for the job is - like JS to do a quick width-match on the labels' natural widths - after the CSS did most of the rest. That is not "bla-bla-blah," that's just knowing the limits of your tools.
The frustration seems to be the impression that CSS should be able to solve any conceivable layout desire on the web, which isn't its charge: CSS is first and foremost made to style web documents, which by-and-large don't fit as easily into the constraint-based-layout box as a traditional desktop app would. Since this kind of desire often crops up in desktop-like SPAs, where JS use is endemic already, it's not wrong to use a little bit more JS to nudge the visual experience a little closer to what you'd see on a desktop app.
I guess my takeaway is, CSS doesn't promise the world, so if you come in expecting that, you'll walk away disappointed. Luckily there are many tools in the web dev toolkit to achieve your engineering desires, and it's not verboten to use them (aside from a philosophical desire to avoid JS, but if the biggest problem for your page when JS is disabled is that the labels are slightly different sizes, I think you're doing a great job already).
I am sure I could discover an equal "simple" example that is easy in CSS but difficult/impossible in GTK.
I doubt it, really. I mean, you could find something for base gtk (which is already out of reach compared to css in ui geometry, because it was done for it), or for the fact that gtk is not a networking engine, but it is just a bunch of predefined containers, calculation phases and signals in C. It is easily extensible in a native way and hides no knowledge about how everything looks or works. Gtk is an example of how you expose distinct particles, pre-implement few useful combinations, and then users build a universe with them. Css is an example of ritualistic black box that hides almost everything about its geometry and requires a non-trivial effort for really basic things. E.g. in css, you have to struggle with dumbest things like a one-pixel vertical scroll in a single-line input. My complaint is not "css is not gtk-like", it is "css is incomplete and unreasoned AF in its own model".
I don't think we can have a reasoned discussion about this if you're going to write off any contention as "bla-blah," so I'm disengaging.
Why isn't this element the size I specified? Or why is there a tiny amount of scroll overflow here when I specify overflow-x hidden? What does vertical-align do and how does it work when inline and inline-block boxes are in an inline flow? etc. etc.
So I would add that the next frontier after learning the proposed foundations is learning how the browser actually determines box sizes and layout, and I think this is difficult to understand, mainly because it jumps straight into the spec, or worse, your browser's layout engine specifics.
https://www.w3.org/TR/css-sizing-3/#auto-box-sizes for instance is a nontrivial subsystem that a CSS dev will easily run into when nesting flex containers, and I think the standard box model of yore wasn't really written to help grok these concepts.
Edit: one particularly hairy explanation from the spec I recently ran into while trying to deepen my understanding of the box model:
"Except for table boxes, which are described in a later chapter, and replaced elements, a block-level box is also a block container box. A block container box either contains only block-level boxes or establishes an inline formatting context and thus contains only inline-level boxes. Not all block container boxes are block-level boxes: non-replaced inline blocks and non-replaced table cells are block containers but not block-level boxes. Block-level boxes that are also block containers are called block boxes."
Not saying this is relevant for the average use case, but I believe even something like the box model is a day-to-learn-lifetime-to-master kind of thing.
I couldn't disagree more. There are a ton of reasons CSS really is hard, even when one understands the box model etc.
E.g.:
1. Hugely non-modular. An element's behavior always depends, to some extent, on styles applied to other elements. Systems full of entangled global state are inherently complex, separate from any other concern.
2. Highly magical. E.g. if you want to control how elements stack with z-index, you need to also know that z-index is ignored for elements that aren't positioned, which in turn means you need to set up your margins differently because positions disable margin collapsing. There's no one "model" to learn; it's a big morass of interconnected rules and edge cases.
3. Extremely fragile. Layout changes that a human user might consider minor often can't be done without significantly redesigning the page.
Of course, problems like these can all be mitigated to various extents. But that takes care and experience; it's not just a matter of reading some articles like you imply.
https://medium.com/@panuviljamaa/why-css-is-difficult-a2cdf0...
Hmmm. That had really not occurred to me. A great post for this little gem alone.
I’m interested in applying CSS Grid as a progressive enhancement specifically targeting browsers supporting it, and keeping what I do today for browsers that don’t.
I don't understand this.
You can appreciate something while still acknowledging its obvious flaws, nothing is perfect.
Instead I think I could agree with people who could point out that it's all trade-offs, and there are some upsides to having fewer autolayout options in UI programming. For example, flexbox and cssgrids enables things you simply wouldn't have attempted before in CSS (you'd have gone with something less expressive, like media-query hard-coding). And any time you nest grids and/or flexboxes you get to rediscover the horrors of autolayout flexibility.
UI is hard and there is no "best". Though it's the emergence of mobile devices that forced the hand to more complex autolayout tools.
> > iphones have poor battery life, I'd like a phone that keeps a charge for a full week at least.
> No you're wrong because android phones also have bad battery life.
>> 21st century capitalism a wealth concentration problem
> No you're wrong because communism is terrible.
One example is ReasonML's async story:
IMO that's a less than ideal response. I'd prefer a more honest response like:A: Unfortunately, we do not offer an async/await equivalent currently. BuckleScript has a Js.Promise type for using Promises. We understand that this is not ideal, and are working on other options.
Look—it's okay that they don't have the feature. Nobody's perfect. But they shouldn't pretend that callbacks are an acceptable replacement because they're "performant".
I've seen so many people use technologies then regret it a year later because they realised what they actually wanted to achieve was at odds with the design goals of the technology.
[1] http://jobjo.github.io/2019/04/24/ocaml-has-some-new-shiny-s...
https://github.com/rescript-lang/ocaml "This branch is 387 commits ahead, 5444 commits behind ocaml:trunk"
If they are semi-serious, then "cromulent" would be a better synonym for "(marginally) acceptable."
(1)https://codepen.io/brettdonald/pen/oRpORG
Coming from a mechanical engineering background, I'm very used to being able to define spatial properties with respect to other elements in CAD, and it just seems lacking in CSS.
Edit: he is using ResizeObserver:
https://developer.mozilla.org/Web/API/ResizeObserver
which hasnt made it past draft JavaScript specification.
I've been building front end stuff for about 25 years and grid is much more straightforward than any approach that's come before it. Tables were a hassle to change, floats were fragile across browsers, flex was (and still is) good, but grid is a step up from all of those.
1. https://caniuse.com/?search=grid
NOOOOO! Please, please, please, please stop second-guessing my choice of browser window width! I bought a nice 27" monitor, and maybe I just want to use the whole thing. Why is your opinion about the amount of space I should be able to use for text more important than mine? I honestly don't care what your research says about optimal character lengths. I deliberately stretched my browser window to be this wide. Please don't override me.
Two, (I know you don't care, but for others reading) there are studies that show that for the vast majority of people, width constraints make it easier to read. So there is good reason to enforce those constraints in the design from a usability perspective, not just a design perspective.
Sorry you don't care about the research. When I'm building a site I absolutely DO care about the research, and what will make it work the best for the largest number of people.
So it depends on what exactly is being measured, which is why I said the overall UX and not something more specific.
This is a bit older, well prior to the days of 4K displays, but lots of interesting stuff nonetheless: http://images3.wikia.nocookie.net/__cb20060729105544/psychol...
Even apart from that, I just see no point in constraining the widths forcefully. Just let the width adapt to the browser width, then each user can size it to his/her preferences and needs of the moment. Win-win for everyone.
[1]: https://meyerweb.com/eric/thoughts/2020/07/01/accordion-rows...
[2]: https://www.gwern.net/About
[3]: https://www.inkandswitch.com/local-first.html
what the hell, its like someone vomited CSS on that page
This is great design that I’m sure converts as well without cheapening your brand and accosting your users.
Delete StandardLayout__GradientWrapper, it served no useful purpose, it only pisses people off.
What is the point of buying a bigger monitor if you're still going to full-screen your browser to the point you can't read anymore? Isn't the point of bigger monitors to show more things at once?
These days we have many websites with giant empty spaces on the left and/or right, all in the name of making the text lines short enough (much shorter than I like them, but that's another rant). Making the browser window smaller often makes the text even smaller, instead of the useless empty spaces. Make some room for my other windows, please! We're not in the 90's anymore where monitors were only large enough for one window.
There's this trend of very wide and ultra wide monitors. I sincerely hope people don't use their browsers full-screen on 3440x1440 monitors.
Unless those empty spaces are supposed to be filled with ads that my ad blocker blocks for me. But that too is another rant.
The other rant is here: [1].
Curious why do you hope people don't use their browsers full-screen? How does someone else's browsing preference affect you? Am I a lesser person if I want to use my browser full-screen on a 5120x2880 retina display?
It seems more and more every year, the user's preference gets sidelined in favor of the web site designer's preference. I never thought it would get to this, but as web sites get more and more opinionated about enforcing their particular stylistic choices, I'm more often than not feeling the need to disable CSS or go into Reader mode. I wish browser developers would provide better tools to override questionable site designs, rather than taking them away. At least I can still change the font size with the browsers (shhhh--don't give them any ideas).
1: https://news.ycombinator.com/item?id=24690133
That is the way your preferences affect me.
This has its drawbacks and some people don't like it, but surely it's better than only using 20% of the width of a wide display.
I would like to see more websites at least include it as an option.
Also this is more complex than using negative margins ever was.