6 ms·
CSS Grid still blows my mind. A syntax that actually makes sense for a visual styling language in CSS? People like to make fun of Javascript but CSS doesn't ge
by dmix 7y ago
CSS Grid still blows my mind. A syntax that actually makes sense for a visual styling language in CSS?
People like to make fun of Javascript but CSS doesn't get enough heat. It was absolutely awful and still is in many ways.
Even Flexbox is a convoluted mess with a strange naming scheme.
CSS Grids just makes so much more sense intuitively for what it's trying to do.
- duxup 7y agoWas CSS even "meant" for layout initially? To me Flexbox is still pretty natural. Names might be weird but there's not a great deal to know and it was the first CSS layout that actually IMO checked enough boxes not to be maddening.
- crispyambulance 7y agoCSS was originally intended as some kind of general-purpose document layout mechanism. It sucked at that at the beginning and ESPECIALLY sucked at web-application layout. Admittedly, part of the reason was because browser-makers would not play nice together and with standards. Meanwhile, desktop application developers have ALWAYS enjoyed decent, predictable layout mechanisms. It is so frustrating that it took the web-based world 2 decades to get their shit together. CSS-grid is built into the CSS standard itself and should have been there from the beginning. It took way too long, but I am glad it's here now.
- irrational 7y agoI blame microsoft. I still can't believe they disbanded the IE team once IE6 had a stranglehold on the browser market.
- playpause 7y agoYou make it sound like CSS Grids is a replacement for flexbox. They each solve very different problems, and they complement each other.
- acdanger 7y agoCan you outline what problems each is trying to solve? I end up using each seemingly interchangeably quite often.
- gherkinnn 7y agoFlex: one dimension and handling an unknown amount of arbitrarily sized elements in any order Grid: two dimensions and handling a known amount of reasonably sized elements
- jasim 7y agoImagine you take a piece of paper, draw 4 vertical and horizontal lines dividing the page into 16 cells. Now when you place an element in any of these cells with width: 100%, they'll take exactly the width of the grid cell. It can't grow beyond that. You have a lot of flexibility in choosing the width and height of each cell, but they are rigid. In case of Flexbox, we don't specify any fixed lines to which the elements will size. Instead, we say general rules saying elements can grow to as much size is available, or stay at the beginning of the row etc. The layout is determined to a large extend by the elements we place rather than on a fixed set of gridlines.
- irrational 7y agoUse CSS Grid for a grid - like a spreadsheet with multiple rows and columns. Use Flexbox for a single row or column. So you might have a 10x10 grid and in the cell in row 3 column 5 you might want to have a bunch of images that are all in a row. Use Flexbox to layout those images.
- nailer 7y agoPersonally I can't be bothered and use grid for both. Why have a separate syntax for one dimension?
- irrational 7y agoHere are 10 reasons why. https://stackoverflow.com/questions/55064488/what-are-the-areas-covered-by-flexbox-which-are-difficult-or-impossible-to-achie https://stackoverflow.com/questions/55064488/what-are-the-ar...
- lazyjeff 7y agoSo is it just me or is the syntax for css grid a bit clunky? I'm talking about specifying ranges using "1 / 4" to mean 1-3 inclusive, or having to separately specify grid-template-rows and grid-template-columns each time. It makes it both hard to learn in the first place, but also hard to remember for casual users (people who use it once a month or so for a new design). Tables don't have the same issue -- once you learn the syntax for tables, you never forget. And even bootstrap is a bit more memorable. But css grid always requires a few trips to stack overflow. Everything else about it is fantastic, but I wish they thought more about intermittent users.
- IggleSniggle 7y agoWhile I agree with it not being as suitable for intermittent users as table, it is also much more powerful. And, you need not separately specify rows and columns. https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template https://developer.mozilla.org/en-US/docs/Web/CSS/grid-templa... And, if you find yourself repeating yourself, you can use variables!
- Vanderson 7y agoI think it can be simple if you try to only solve a few things with grid. When I first learned grid, I could only figure out one or two things. Then I got ok with a few things, then I went crazy and made a magic framework. Now, I only use primarily these: display:grid; grid-gap: [value]; grid-template-columns: 1fr max-content, etc...; That is 90% of my use case for grid. For entire page layouts, I would use grid-area so I can place stuff where I want and move it around on mobile. Grid rows are implicit with the above code, so I so I have a mini-framework with utility classes for a few different column scenarios. (3 columns, column with compressed/flexible combinations for things like forms, etc...)
- dkersten 7y agoI personally dislike it. Sure, its powerful and is maybe an improvement over what we had before, but maaaan its so complex compared to desktop UI libraries I've used, especially QML with columns, rows, grids and anchors. Simple example, in the Grid Garden, on Level 3: grid-column-start is the grid cell it starts on, but grid-column-end is the cell after the one it ends on (half-open range), but on Level 4 when start is 5 and end is 2 its the opposite: the end column is included but the start one is not. Also, why would you do it in reverse like this even? And in Level 6, why -3 and not -2? Honestly, I'm more confused now than I was before. At least placing the top-left corner and using span makes sense to me. I guess its better than making grids in other ways, but why did it have to be so weird?
- disconcision 7y agoI believe start and end are numbered according to the lines between cells, not the cells themselves