1-Line CSS Layouts
1linelayouts.glitch.me
1linelayouts.glitch.me
On topic: these are great. I am not sure why grid is one of the most useful, yet underutilized set of features in CSS. Could it have something to do with the fact that there are literally a 1000 ways to accomplish the same thing with it? It's been years since their introduction and I am still very much not comfortable and have to use MDN every time I have to do anything.
Is it just just my old age? Am I alone in this?
First time I tried to use grid layout, we had to roll back the changes because it didn't work in IE11... now that IE11 support is being phased out in most places it might be more usable now?
I do agree that the grid stuff is a little too robust. I'm also finding myself looking it all up again every time I need to use it... but maybe I just don't have the muscle memory down yet like I do with flexbox.
Between last year and this year, our IE11 visitors shrank from a few percent (I think it was 5% during the week, under 1 on the weekend…) to under 1, and I got permission to kick IE11 support. Already implemented the first grid and can’t wait to use CSS variables. It’s like I suddenly landed in the future :)
I think it has a lot to do with perceived browser support and lack of familiarity. Perhaps also a bit of CSS fatigue: “I just learned flex bix and that’s good enough.”
The CSS grid still works worse with the printing page breaks than the tricks with the floats and margins.
I've been using CSS since it first [barely] appeared in IE3, but I've been behind on fully getting to know flex and grid. Didn't know about aspect-ratio at all.
Maybe that says more about the amount of attention I've been paying, but I learned a lot from these examples.
I have tried CSS Grid Garden in the past. I don't remember a damn thing from it.
And Classic Holy Grail Layout is not a one-liner but this:
.ex5 .parent {
display: grid;
grid-template: auto 1fr auto / auto 1fr auto;
}
.ex5 header {
padding: 2rem;
grid-column: 1 / 4;
}
.ex5 .left-side {
grid-column: 1 / 2;
}
.ex5 main {
grid-column: 2 / 3;
}
.ex5 .right-side {
grid-column: 3 / 4;
}
.ex5 footer {
grid-column: 1 / 4;
}
For the note, in Sciter (flow+flex units) that is definable as main {
flow:grid(1 1 1,
2 5 3,
4 4 4);
}
main > :nth-child(5) { /*middle section */
width:*; /* takes all available space */
height:*;
}
https://terrainformatica.com/2018/12/11/10-years-of-flexboxi...The job of assigning elements to their places could also use named areas:
.ex5 .parent {
display: grid;
grid-template: auto 1fr auto / auto 1fr auto;
grid-template-areas: "header header header"
"left main right"
"footer footer footer";
}
.ex5 header {
grid-area: header;
}
.ex5 .left-side {
grid-area: left;
}
.ex5 main {
grid-area: main;
}
.ex5 .right-side {
grid-area: right;
}
.ex5 footer {
grid-area: footer;
}
Or you could lean on auto placement more heavily: in the original code, the left/main/right grid-column declarations are superfluous, and `1 / -1` is arguably clearer than `1 / 4` for the header and footer: .ex5 .parent {
display: grid;
grid-template: auto 1fr auto / auto 1fr auto;
}
.ex5 header,
.ex5 footer {
grid-column: 1 / -1;
} .ex5 {
flow: grid(header header header,
lside main rside,
footer footer footer);
border-spacing: 3px;
}
main { float: "main"; }
footer { float: "footer"; }
In case of Sciter, single property flow and flex units define everything that flexbox and grid can do with 20+ properties. And note: flexbox breaks existing CSS box model, flow/flex units - do not.See: https://terrainformatica.com/w3/flex-layout/flex-vs-flexbox....
[1] https://css-tricks.com/snippets/css/a-guide-to-flexbox/ [2] https://css-tricks.com/snippets/css/complete-guide-grid/
This multi-part MDN guide worked for me. Had to read it twice.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_La...
All the techniques revolve around the flexbox and grid selectors. In that sense, it is a good starting point (or at least, was) for a CSS developer wanting to have the latest tricks in his arsenal.
I said I didn't mean to be cocky. It just makes me think people don't even touch CSS because if I publish an article saying "this is how you print hello world in C" people wouldn't care.
In 2011, “display: table” was cutting edge; we finally had few enough IE6 and IE7 users that it was practical to pull off, albeit with “<!--[if IE lt 8]><table><tr><td><![endif]-->” hacks.
I still had to deal with IE-specific bugs like the fact webfonts didn’t work in IE8 when put in an IFRAME — but did work in IE9 when rendering in IE8 mode. This wasn’t limited to IE: Safari had a bug where you couldn’t legibly print a page with webfonts on them, requiring a Safari-specific hack to disable webfonts in the print CSS.
Professional web developers were not using stuff like “display: flex” or “display: grid” in production until the late 2010s, when Edge and Chrome was finally reducing the number of Internet Explorer uses to a sane level.
[1] https://blog.chriszacharias.com/a-conspiracy-to-kill-ie6
These two only existed theoretically. For anyone actually earning a living with the frontend they didn't exist because:
- grid kinda existed in IE, but not in other browsers. Well, you could build a site that only targeted IE, but in 2007 this was already being really frowned upon and out of vogue.
When grid was finalized, it was a different version of the spec, not entirey compatible with IE's. Chrome and Firefox only got grid in 2017.
- flex was only partially supported by browsers until 2012 when it was fully supported, but behind a prefix. Full support without a prefix only appeared in 2013.
I mean, I love the fantasy world you have constructed, but there are people who actualy do frontend and do actually remember the anciaent histroy of checks notes the past 10 years or so
I really wish Display: Grid was practical to use back in 2009. It would had been a lot more straightforward than the “Display: Table” stuff I did instead.
Indeed. There's a reason caniuse lists browsers all the way back to 2009 or so :D
So yes. This is useful to significantly more people than you imagine.
I added emphasis so you don't twist other people's words in the future.
In fact, the single most important resource I wish for of this kind, would be a reference page that shows all common layouts and tech-stack agnostic examples of popups, overlays, off-canvas sidebars and such using the most up-to-date implementation so we wouldn't have to include a huge CSS framework for something that's a few lines of modern CSS supported by evergreen browsers.