News for hackers. Stuff that matters.
Re:Full-Bleed Layout Using CSS Grid by preommr on Monday October 05, 2020 @05:03PM (#24692022)
I hate that people use CSS Grid like this. For some reason, I see so many people reach for CSS Grid like it's the de facto solution for responsive design.

This is a bad design because you're tying the child elements to the grid layout of the parent. If you added an extra column in the grid, you'd have to go and adjust it for the full bleed elements.

IMO a better solution would've been to just use a column layout with flex box, where the children are containers at standard sizes (e.g. full-bleed, 80-characters, etc.).

Yes it adds like another tag or two, but it's semantically more sound. And from that extra markup we get a lot more flexibility, e.g. going from column layout to a slide show or something if someone wanted.

CSS Grids are good for grids i.e. layouts where you want control over flow in both axes. This is not a grid. You have one column of data where you are controlling whitespace.

This has become a real pet peeve of mine because it seems like so many people love css grid when it's actual use case is fairly rare.

Edit: I also want to add that this creates an uglier layout if you have variable width children. Because you'd essentially create a full-bleed container element just to add a non-full bleed child to it.

And I am sorry that this came across as kind of aggressive, this is something that's really been irking me with recent web dev trends. And I feel like a crazy person confused over why the world suddenly decided on Css Grid all day every day.

Re:Full-Bleed Layout Using CSS Grid by jstummbillig on Tuesday October 06, 2020 @03:50AM (#24695569)
This displays a very mediocre grasp on, at the very least, web semantics and CSS Grid. (Also, an emotional disposition against a simple piece of web technology. Wild.)

> This is a bad design because you're tying the child elements to the grid layout of the parent

Apart from that sentence carrying very little internal logic and abusing the word "because", there is a simple fix to what, I think, is your point: Name your grid areas.

There is absolutely nothing in CSS Grid specifications that urges you to fill in all the possible areas, or, in fact, any of the areas. Or make it 2D. If you can use it to solve your layout problem in an elegant way, that's a good thing. The solution in the linked article is semantically sound and elegant -- obviously far more elegant than the proposed alternative of adding control markup to every single child.

Re:Full-Bleed Layout Using CSS Grid by Aeolun on Tuesday October 06, 2020 @07:11AM (#24696521)
You can use the same trick in a flexbox container?

Set every * to max-width: 65ch and then have the same full-bleed class to go to width: 100%.

I agree with OP that using grid for this is a bit misplaced. But realistically, it probably won’t be a problem.

Re:Full-Bleed Layout Using CSS Grid by joshwcomeau on Tuesday October 06, 2020 @08:08AM (#24696832)
This doesn't work because `65ch` means very different things depending on the font-size. You need to apply it to a parent class, so that it picks the base font size (I'm not actually sure how this works but in practice it seems to base it on the child <p> tag).

I also don't like the idea of "reaching in" and setting widths on all children. Feels like this could cause problems, especially on replaced elements like images/videos. Not to mention that it just feels wrong when combined with a component architecture, where I might expect a <Heading> component to control its own destiny. In fairness, my solution also reaches in to apply a grid-column, but grid-column is a property that only makes sense when combined with a parent's `display: grid`. So it bothers me less.

Enough people have brought this up that I wonder if I should have addressed it in the article... but then I realize, it's not my job to argue against or "disprove" all alternative ideas. I'm not claiming that my way is the best way, I'm just sharing a cool trick I found :)

Re:Full-Bleed Layout Using CSS Grid by knathan on Tuesday October 06, 2020 @10:06AM (#24697755)
There really aren't any scenarios I can think of that an element would need to have `grid-column` set without being wrapped in another grid, so for that reason it is generally safer to set `grid-column` on all children than it is to set `max-width`. I would be surprised if I added an element only to discover that its width was being modified by a wildcard rule, less so with `grid-column` because grid placement is arguably the concern of the grid.

As a side note, I like this technique and have already had a good opportunity to apply it instead of the old padding & negative margins method or even flexbox + stretch (and I like flexbox), neither of which actually worked for this very specific case.

Re:Full-Bleed Layout Using CSS Grid by Aeolun on Wednesday October 07, 2020 @06:33AM (#24706888)
> I'm not claiming that my way is the best way, I'm just sharing a cool trick I found :)

I agree. It’s not that I really think one way is better or worse.

I like flexbox more, but since you’re not working in my codebase, you can do whatever you want ;)

Re:Full-Bleed Layout Using CSS Grid by detaro on Tuesday October 06, 2020 @08:09AM (#24696836)
Doesn't that run in the "ch depends on font and font-size" problem e.g. with headings vs paragraphs again if you don't use wrappers?
Re:Full-Bleed Layout Using CSS Grid by Aeolun on Wednesday October 07, 2020 @06:34AM (#24706896)
Hmm, that’s definitely possible, but then I think we probably shouln’t be using that magic unit to begin with.
Re:Full-Bleed Layout Using CSS Grid by detaro on Wednesday October 07, 2020 @07:10AM (#24707068)
Why? It specifically exists to make things dependent on the font, and sizing text columns based on the size of the body text, and have other elements follow that, also makes sense.
Re:Full-Bleed Layout Using CSS Grid by Aeolun on Thursday October 08, 2020 @08:45AM (#24718602)
Yes, but with it being dependent on the current font size, its a tad hard to use effectively.

You can make the container have a sensible weight to keep all elements within it, but you cannot have the children contain their own destiny in a consistent manner.

Re:Full-Bleed Layout Using CSS Grid by lloydatkinson on Tuesday October 06, 2020 @04:35AM (#24695781)
I fail to see anything in your reply that disputes anything OP said
Re:Full-Bleed Layout Using CSS Grid by ss3000 on Monday October 05, 2020 @06:06PM (#24692579)
Widespread flex gap support will probably eliminate 95% of grid usage in my apps today: https://caniuse.com/flexbox-gap

And what a surprise, it's just Safari holding us back again. =_=

Re:Full-Bleed Layout Using CSS Grid by matthewmacleod on Tuesday October 06, 2020 @07:23AM (#24696593)
In fairness, this feature was only released in Chrome a couple of months ago, and has in the past week been merged into WebKit: https://trac.webkit.org/changeset/267829/webkit
Re:Full-Bleed Layout Using CSS Grid by ss3000 on Wednesday October 07, 2020 @03:37PM (#24711843)
Fair enough, I guess both Chrome and Safari were holding us back until a few months ago haha.

Really ecstatic to see that it's going to be in Safari soon though! Thank you so much for sharing! Really made my day.

This is why I love Hacker News.

Re:Full-Bleed Layout Using CSS Grid by desert_boi on Monday October 05, 2020 @09:59PM (#24694093)
Chrome got in in May finally...Firefox has had it for years. One thing I really missed in Chrome and Safari.
Re:Full-Bleed Layout Using CSS Grid by gkilmain on Monday October 05, 2020 @10:05PM (#24694114)
Awesome - didn't know this was a thing.
Re:Full-Bleed Layout Using CSS Grid by Dahoon on Monday October 05, 2020 @07:40PM (#24693297)
The new IE.
Re:Full-Bleed Layout Using CSS Grid by artificial on Monday October 05, 2020 @09:34PM (#24693968)
Wouldn’t that be Chrome? The ubiquity leads to lazy developers testing only on it. Maybe some fancy SVGs saying “Best viewed on Chrome!” To really rub it in :)
Re:Full-Bleed Layout Using CSS Grid by DarkWiiPlayer on Tuesday October 06, 2020 @02:53AM (#24695310)
> SVGs saying “Best viewed on Chrome!”

HA! Chrome absolutely SUCKS at displaying SVGs. I rarely use them and I've already found two stupid bugs.

One super weird one (probably too much caching) where an animated element in a <use> clone didn't inherit colours while its non-animated siblings do. This one is fixed now.

What isn't fixed yet is that `filter: hue-rotate(90deg)` applied to an SVG child element doesn't do anything (in firefox it does), is a pain in the ass because SVG filters, while more powerful, are much harder to set up.

Re:Full-Bleed Layout Using CSS Grid by progers7 on Tuesday October 06, 2020 @08:26AM (#24696960)
SVG filter support in Chromium is actively being worked on, primarily led by an incredible engineer at Opera ([email protected]). This work has been ongoing for almost a year and should complete in Q4. Please star https://crbug.com/109224 for updates (stars also help prioritization).
Re:Full-Bleed Layout Using CSS Grid by realusername on Tuesday October 06, 2020 @03:50AM (#24695568)
Safari also has its share of SVG bugs, like this one: https://stackoverflow.com/questions/31150919/svg-background-...
Re:Full-Bleed Layout Using CSS Grid by artificial on Tuesday October 06, 2020 @11:23AM (#24698654)
Going to codepen this later and see what’s up. I haven’t used them beyond toy setups since it’s usually a hassle, I always get inspired by the Stripe site.
Re:Full-Bleed Layout Using CSS Grid by greggman3 on Monday October 05, 2020 @10:18PM (#24694181)
No, the definition of "the new IE" is to not support the latest features.

Pick some other phrase for "most popular"

Re:Full-Bleed Layout Using CSS Grid by lucideer on Tuesday October 06, 2020 @06:09AM (#24696236)
The definition of "the new IE" is not not supporting the latest features (IE had plenty of "new" features—see e.g. filters, VML, XMLHttpRequest). The issue with IE was that it supported it's own proprietary features without consultation nor coordination with competitors. Something it was only able to do due to its market monopoly.

Yes, Chrome does this too.

It's slightly better in that it tends to submit them to standards bodies after implementing them, but most of the time that's WHATWG which is a much less democratic body than others, and mostly Google-led. Either way Chrome's market monopoly leave competitors with little choice in the standards process.

Re:Full-Bleed Layout Using CSS Grid by tannhaeuser on Tuesday October 06, 2020 @03:01AM (#24695332)
Yeah "web standards" my ass - with WHATWG 100% just being Chrome devs, and W3C a pay-as-you-go wannabe "standardization body" financed by Google (and long out of the game of doing anything meaningful except CSS) so-called web standards are more of a monopolization and extortion instrument than anything else. Web heads seriously need to wake up rather than making it ever more complicated.
Re:Full-Bleed Layout Using CSS Grid by keeganpoppen on Tuesday October 06, 2020 @01:13AM (#24694905)
he is 100% right that IE's ubiquity is what caused the problem to begin with. well, that and microsoft getting arrogant because of it.
Re:Full-Bleed Layout Using CSS Grid by earthboundkid on Monday October 05, 2020 @09:22PM (#24693903)
You mean the common JS environment that doesn’t support fetch, Node?
Re:Full-Bleed Layout Using CSS Grid by russelg on Monday October 05, 2020 @08:04PM (#24693491)
Very disingenuous of you. IE was a trashfire because it refused to do anything in a standard way, meaning it had to be specially catered for. Safari is slow to follow the standards but at least its compliant. A engine that isn't Chrome is very essential for keeping the web open, especially since Firefox user share keeps going down.
Re:Full-Bleed Layout Using CSS Grid by schwartzworld on Monday October 05, 2020 @08:20PM (#24693602)
Safari has absolutely ignored standards when it suits apple. That's why, for example, you can't rely on PWAs on Apple products.
Re:Full-Bleed Layout Using CSS Grid by manigandham on Tuesday October 06, 2020 @12:58AM (#24694835)
IE actually created many of the standards we take for granted like XMLHttpRequest. [1] It was the innovator for a long time until priorities changed and the IE team was disbanded leading to the stagnation.

Microsoft definitely takes the blame in keeping it poor for so long but this situation is nothing like Safari which has refused to implement standards that already exist, as well as messing with others in unintuitive ways.

1. https://schepp.dev/posts/today-the-trident-era-ends/

Re:Full-Bleed Layout Using CSS Grid by fenomas on Monday October 05, 2020 @11:11PM (#24694410)
A browser engine that's primarily used on platforms where it's mandatory, and cannot be uninstalled or replaced, is "very essential for keeping the web open"?
Re:Full-Bleed Layout Using CSS Grid by asddubs on Monday October 05, 2020 @08:13PM (#24693546)
ie was also a trashfire because of the release/update model, holding the entire web back because it was so far behind standards (ie6 was actually ahead of its time on release, but then didn't get updated for ages). safari, especially on ios where you can't even get any other browser engines, and the safari version is tied to the operating system version, follows that same model with the same consequences. not as painful these days, since the web has come a long way already, but you can definitely see the parallels
Re:Full-Bleed Layout Using CSS Grid by keeganpoppen on Tuesday October 06, 2020 @01:16AM (#24694918)
unsure what part of this is cause for downvoting-- it is absolutely correct. it's not even invalidating other peoples' observations. people are weird (or ignorant (or both))...

edit: oh and i guess now that i upvoted it it's not grey anymore xD

Re:Full-Bleed Layout Using CSS Grid by realusername on Tuesday October 06, 2020 @03:53AM (#24695584)
Safari has a lot of issues outside of just being behind the standards. I've encountered background and z-index jank, form issues, SVG issues and even mouse event issues. If you are a web developer, there's a good chance your codebase has Safari bugfixes.
Re:Full-Bleed Layout Using CSS Grid by SiVal on Monday October 05, 2020 @09:51PM (#24694062)
slow to follow the standards

Safari is not only slow to follow the standards, it is slow to advance the standards. I'd be more likely to believe the spin that Apple just wants to make sure things are done well on the web if it appeared that they were trying as hard to add good, new capabilities to the web platform as they are to add good, new capabilities to iOS.

A engine that isn't Chrome is very essential for keeping the web open

Also essential is for the open web to be competitive with closed alternatives, or the fact that it's open will matter less and less. Apple is quite willing to provide competition for Chrome. It does it with iOS.

Re:Full-Bleed Layout Using CSS Grid by greggman3 on Monday October 05, 2020 @10:23PM (#24694209)
Apple is only able to do this because of the monopoly of browser engines for 1.5 billion iOS devices. If they allowed (or were forced to allow) other browser engines then likely a large number of users would switch to another browser, forcing Apple to compete for features.
Re:Full-Bleed Layout Using CSS Grid by manigandham on Tuesday October 06, 2020 @01:13AM (#24694906)
What's that say about the quality of Safari then?
Re:Full-Bleed Layout Using CSS Grid by rimliu on Tuesday October 06, 2020 @03:32AM (#24695486)
How quickly people forget who brought canvas, CSS animations, etc.
Re:Full-Bleed Layout Using CSS Grid by ehnto on Tuesday October 06, 2020 @12:55AM (#24694812)
Firefox and Chrome still don't agree on how tables should work.
Re:Full-Bleed Layout Using CSS Grid by tekkk on Monday October 05, 2020 @06:05PM (#24692567)
It's surprising how rarely I even consider using CSS grid and every time I do, I still figure out a way to do it with flexbox. Now this depends of course on what you are doing, but for simple things, and you should keep things simple more often than complicated, flexbox is still as valid as it was before.

Maybe my layouts aren't as fancy as those who know how to neatly proportion their boxes with CSS grid using golden ratios, but I'm quite satisfied that they work and are easy to understand for anyone who knows a thing or two about flexboxes. Sometimes I might have to add an unnecessary wrapper, I admit that. But oh well.

Re:Full-Bleed Layout Using CSS Grid by __sisyphus__ on Monday October 05, 2020 @09:11PM (#24693844)
I agree. Grid seemed great in theory, but in practice I almost never find myself using it. The number of use cases that flexbox doesn't satisfy is quite small, and the Grid syntax is a bit more tedious. It's just not worth the trouble most of the time.
Re:Full-Bleed Layout Using CSS Grid by frankzander on Tuesday October 06, 2020 @03:20AM (#24695420)
Seems like you are the style police ;) According to the creators of the Grid you can use it for whatever you want however you want. So there is no right or wrong. The last yeas I often hear to voices saying "this is wrong do it so" or something until I realized, that a elegant way in CSS is mostly not adaptable from one html layout to another (across CMS ). So everyone has to find his own way to write clear code which is manageable. There is no gold path.
Re:Full-Bleed Layout Using CSS Grid by atoav on Monday October 05, 2020 @09:20PM (#24693899)
I like CSS grids for global layout stuff because of the layout flexibility it gives you when it comes to different screen sizes and orientations, without having to use js when you need to swap the order of things around (and at some point you will have to eventually unless it is a very simple page). This helps separating the markup from the styling even further so it is rather a good thing.

I would — however — never had the idea to abuse it like that. Why not just limiting using max-width on your text-related tags?

The only problem I ever had with that is that markdown generated HTML will wrap <img> into <p> if it follows the standard and as of now there is no CSS way of selecting p without child of type IMG or p only with child of type img..

Re:Full-Bleed Layout Using CSS Grid by innocenat on Tuesday October 06, 2020 @02:11AM (#24695136)
max-width on text do have a problem: you cannot set margin on the them. Say, blockquote, unordered list, etc.
Re:Full-Bleed Layout Using CSS Grid by exogen on Monday October 05, 2020 @06:28PM (#24692753)
This alternative falls apart as soon as you want to put a border or box-shadow around the content column while still having full-bleed elements.

Now you're limited to having it individually around each group of elements before/after any full-bleed content, instead of the entire set of content.

Re:Full-Bleed Layout Using CSS Grid by kumarharsh on Tuesday October 06, 2020 @12:04AM (#24694583)
Not necessarily. I'm on mobile, so can't link to code right now, but here's how it would happen:

You can have another .background element which spans all the rows (using grid-row-start and grid-row-end) and positioned in the centre column. Apply the shadows on it, and keep it before the content div in DOM order. That should do it.

Re:Full-Bleed Layout Using CSS Grid by bmuon on Monday October 05, 2020 @07:57PM (#24693431)
The parent-child problem you mention can be addressed with names. Children can say "grid-name: footer". This is just a hint for the parent to decide where to place it in the grid. Then the parent can use grid-template-areas to arrange its children. You no longer need to change the children if you're adding columns to the layout.

(I agree with you on this simple layout)

Re:Full-Bleed Layout Using CSS Grid by chrisweekly on Monday October 05, 2020 @07:15PM (#24693092)
You're not alone! I strongly prefer flexbox too. Besides the points you mention, excessive use of grids leads to "designing to the grid" instead of letting the content and context dictate flow.

Tangent: I also remember doing ridiculous things with nested tables during the original browser wars (circa 2001?) and consider it a "first-world problem" to be choosing among standards-based styling mechanisms.

Re:Full-Bleed Layout Using CSS Grid by artificial on Monday October 05, 2020 @09:35PM (#24693977)
The tables haven’t died for email layouts. Email presentation is horrific. Outlook with its special IE is oh so much fun.
Re:Full-Bleed Layout Using CSS Grid by kumarharsh on Tuesday October 06, 2020 @12:06AM (#24694592)
Outlook doesn't even have IE btw... It has a custom MS Word compliant HTML parser/renderer (Facepalm emoji)
Re:Full-Bleed Layout Using CSS Grid by artificial on Tuesday October 06, 2020 @01:50AM (#24695051)
You’re correct. They switched from IE to Word https://www.litmus.com/blog/a-guide-to-rendering-differences...
Re:Full-Bleed Layout Using CSS Grid by asddubs on Monday October 05, 2020 @05:48PM (#24692416)
there's virtue to having smaller isolated components when possible. kind of a weird example, but the other day I tried to make a huge table responsive (that needed to be paginated badly, but that was an issue out of my reach) - I found out that chrome actually maxes out at 1000 rows for display:grid, and then your layout just breaks. I converted it to flexbox and getting it to look the way I wanted was way easier than I expected, plus I could support ie11 without having to do the weird ms grid syntax. I imagine it's also faster for the browser
Re:Full-Bleed Layout Using CSS Grid by highwind on Monday October 05, 2020 @05:31PM (#24692274)
This reminded me of days where we used <table> to do layout.
Re:Full-Bleed Layout Using CSS Grid by rimliu on Tuesday October 06, 2020 @03:34AM (#24695494)
Anyone who have usee tables for layout (I have) knows that it is nothing like that.
Re:Full-Bleed Layout Using CSS Grid by anotheryou on Tuesday October 06, 2020 @05:35AM (#24696085)
My use case would be to style markdown exports and it's really a pain to add divs everywhere and it screws with the timelessness of your document. A few years ago I used js to achieve full bleed.
Re:Full-Bleed Layout Using CSS Grid by ron0c on Tuesday October 06, 2020 @08:06AM (#24696814)
I can tell you why I, a sys admin interested in dabbling in html/css for my own personal website, looked into CSS Grid.. Firefox Developer Start Page. Right there in the middle.
Re:Full-Bleed Layout Using CSS Grid by sleavey on Tuesday October 06, 2020 @02:20AM (#24695184)
Could you show some example CSS for your alternative suggestion by any chance? I'm not quite sure what you mean about using flexbox this way.