Readit News logoReadit News
CGamesPlay · a year ago
I was very intrigued by the animated demos, but apparently the animation is not accomplished with CSS :(

I definitely learned flexbox and thought to myself "this is good enough", and haven't really pushed myself to learn grids. It does seem like there's some reason to prefer grid [0], but it overall I've never needed to do anything that can only be done with grid (except data tables, for which I use actual tables).

[0] https://css-tricks.com/css-grid-replace-flexbox/

wonger_ · a year ago
That's great that you've learned a tool that covers all your needs.

I've only used grid for responsive image galleries like https://labs.jensimmons.com/2016/examples/image-gallery-grid... or responsive cards like https://every-layout.dev/demos/grid-cards/. `grid-template-columns` is good to learn. `grid-gap` is convenient. Flexbox seems to handle everything else.

But I'm still iffy about grid template areas. The article makes a case for easily adjusting layouts per breakpoint, or "for team members who might need to change a layout." Maybe I'm just not the target audience.

bobthepanda · a year ago
Grid template areas is very similar to traditional print layouts that are constrained with both a width and height. If you need something like grid-auto rows it is less useful.

But what’s nice about it is that, if you want them, grid areas are extremely declarative. With non-area templating, you are defining the layout based on the items, and that can be challenging.

yurishimo · a year ago
If you can target (somewhat) modern browsers, then you can also use `gap` with Flexbox. Works great!

https://caniuse.com/mdn-css_properties_gap (no IE 11 support)

higgins · a year ago
A fun tool for grid learning: https://cssgridgarden.com/
sensanaty · a year ago
Flex is good enough for most things, but grid has its place. Responsive grids (think of those 3 column card layouts that shrink to a single card per row layout on small screens), page layouts like dedicated sidebar areas, resizable elements that should stick to a certain layout despite the resize, etc.

Nothing stopping you from using both as necessary, combined it's a very strong layout tool

lenkite · a year ago
"No, Flexbox isn't "good enough" https://www.youtube.com/watch?v=MWWcZzossc8
happytoexplain · a year ago
Wait, '1/3' isn't a fraction, it's a range from 1 to 3? Why in God's name would they choose that syntax? Ranges have plenty of reasonable, well known syntaxes in programming. E.g. 1..3
appointment · a year ago
The very first thing you need to know about CSS is that it uses the language of print layout, not programming.

A lot of the problems programmers seem to have with CSS probably stem from this misapprehension.

layer8 · a year ago
Do you have a reference for this particular usage of slash? In print, “x / y” is often used to mean “item x out of y” [0], for example in page numbers. I’m only familiar with using slashes for ranges in ISO 8601, where it has purely syntactic reasons and (AFAICT) doesn’t adopt any preexisting convention.

I imagine the slash in CSS grid is for similar syntactic reasons, because the syntax also admits hyphenated identifiers [1] (custom-ident), which precludes the use of “-”. (They could have used a range operator like “~” or “..” though.)

[0] https://en.wikipedia.org/wiki/Slash_(punctuation)#Numbering

[1] https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column...

happytoexplain · a year ago
As far as I know, 1/3 means "one of three" in print - which actually is division ("1 of 3" means the subject's position is 1/3 of the way through).
davidmurdoch · a year ago
CSS uses "/" for division (fractions) inside `calc`, so I don't think not understanding the language of "print" is where the frustration comes from nowadays. I think CSS is also part programming language now.
gedy · a year ago
While I like grid functionality, the syntax is really different from lot of other CSS, and it's confusing imho. It's like this corner where you can see they either developed it in isolation or felt they were "going to do it right this time" or something.
Izkata · a year ago
Numbers are far from the only thing that can go there, including multiple words on each side of the slash: https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column...
jonwinstanley · a year ago
Imagine telling a programmer that in CSS - !important means "important!", not "not important" :-)
xp84 · a year ago
I haven't been able to grasp either grid or flexbox. The last layout strategy I was decent at was floats. This article made me feel confident to use a css grid next time I am designing a layout. Well made! Thank you.
Brajeshwar · a year ago
If you were there with floats, Grid and Flex will be a walk in the park for you. Give it a day or two and try out a few layouts. And unlike the struggles with browsers, these two seems to just work. In-fact, they are kinda boring.

There are a lot of articles, some really good but I read through two of CSS-tricks articles and that is all there is.

- https://css-tricks.com/snippets/css/a-guide-to-flexbox/

- https://css-tricks.com/snippets/css/complete-guide-grid/

hyperbolablabla · a year ago
Those articles are my bible. I have them almost memorised but for the more esoteric things I still consult them. Invaluable resource!
phforms · a year ago
I think you can get away without learning grids, but flexbox is a must - given its convenience over the old “float-hacks” and its omnipresence in modern CSS.

Besides the already mentioned css-tricks articles, I recommend checking out the guide to flexbox from mdn[1] (in the side menu there is also one for grids) as well as the reference to “CSS flexible box layout”[2]. These helped me get a deeper understanding about the concepts behind flexbox and how the properties and their shorthands actually work.

[1]: https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layou...

[2]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_flexibl...

dsego · a year ago
I feel like flexbox is the float grid system done right, and you can lay out children either vertically or horizontally, whereas floats with the clearfix hack were only laid out as rows. But it's still mostly one-dimensional with possible wrapping, so the trick is to nest and stack. With grids it's different, a grid has a template and then the direct children occupy those predefined areas, which is more static than flexbox and the grid doesn't affect other nested elements, which is a limitation, but subgrid should change that.
agumonkey · a year ago
If you managed to understand floats (a rare feat) you'll have a blast with flex / grid :)
kolme · a year ago
Floats are not weird. They were just utterly misused, using them for layout is an ugly hack.

They were conceived to float text (or other elements) around static elements. Think text floating around a picture, like this:

https://tco-forum-uploads.s3.amazonaws.com/original/3X/0/3/0...

xp84 · a year ago
Even though it’s been a long time, I feel compelled to point out that I was only decent at floats, I was never good at it. LOL
sbergot · a year ago
Grid has a lot of features but flex is simple enough and still very powerful
orthoxerox · a year ago
The last layout strategy I was decent at was <table>, so you should be fine.
nicoburns · a year ago
Grid is basically `<table>` with extra functionality (in fact in my project we are emulating table layout using CSS Grid with good results). If you can do <table> then you can do grid.
Alifatisk · a year ago
Related:

Grid Garden https://cssgridgarden.com

Flexbox Froggy https://flexboxfroggy.com

deskamess · a year ago
Is there a pre-intro version of this document? I am lost at the Introduction itself and not able to get past it. In particular:

> If I need to position child items within the grid, I need to specify the line number for each item by using grid-column.

Stuck at what is 'line number' in this context? I tried to force my way through it hoping context would fill it in but immediately got stuck at fractions like '1 / 3' followed by '1 / 4'.

JoeCianflone · a year ago
Line numbers are the dividing lines between columns. If you have 2 columns you’ll have 3 lines: |a||b| the two lines in the middle actually count as 1. Hence 3 lines. So 1/3 is not a fraction its column span. It means “start at line 1 and end at line 3”.
masklinn · a year ago
If you scroll down just a bit, the article provides a live demo so you can play with the system and see what’s happening.

The “line numbers” (not a great name) are the column edges. So 1/3 goes from edge 1 (the left-most) to edge 3, spanning 2 full columns.

talkingtab · a year ago
Highly recommended for CSS Grid is Jen Simmons Mondrian with auto flow. https://labs.jensimmons.com/2017/01-011.html. Try 'C' and 'D' then change the window size. Also the youtube video that goes along https://www.youtube.com/watch?v=qNtJ5p3h2A4.

Just very cool.

The one thing about auto flow I wish I understood was how to detect, and fill, gaps. If I have some random collection of differently sized objects, how do I ensure that auto flow leaves no gaps? Or even detect that so I can add something?

tomw1808 · a year ago
I hope that's not a stupid question, but why define the syntax as 1/2 and 3/4 (divider) and not 1-2 (column 1 _to_ column 2) and 3-4 or 1->2 or something like that?
sapling-ginger · a year ago
The column number can be negative. 1--1 vs 1->-1 vs 1/-1 ?
elteto · a year ago
a:b is almost universal as a range designator at this point. / is a _terrible_ choice, especially in a context where a fractional value would also make sense.

That was just an objectively bad syntax choice, but probably keeping on track with CSS.

Izkata · a year ago
Arrow maybe, but the spaces around it are there for a reason - numbers aren't the only valid values: https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column...

Because of how spaces are already used to separate values in CSS (not to mention our own regular intuition when dashes are involved), this:

  grid-column: 4 somegridarea / 6;
  grid-column: span 3 / 6;
  grid-column: span somegridarea / span someothergridarea;
is much better than these:

  grid-column: 4 somegridarea-6;
  grid-column: span 3-6;
  grid-column: span 3->6;
  grid-column: span somegridarea-span someothergridarea;
  grid-column: span somegridarea->span someothergridarea;

kurtdev · a year ago
Wow, I just love interactive blog posts like this. For grids I can really recommend just playing around with grid areas in a tool like https://grid.layoutit.com/

I've been using the site to plan my grid layouts for a couple of years now and it just makes spacing so much easier