Live data from Hacker News

Learn CSS

web.dev

171–180 of 196 posts

Re: Learn CSS

#171
post #99

Earlier quoted context omitted.

> Until somebody has another similar box so they reuse login-box a bunch in your application Then they make `.box` and include it as a mixin. Like CSS developers have done for a decade (and which tailwind itself does using PostCSS) > Tailwind doesn't make you copy and paste Yes it does. Moving all styles into individual elements without reuse is copy and paste.

> Yes it does. Moving all styles into individual elements without reuse is copy and paste Tailwind all but assumes you will be using something that allows you to extract HTML into components, be that something like React or Vue, or classic partials in a server-side templating language like Twig. You reuse the entire component, rather than just the CSS, which IMO is far better aligned with how apps are actually built.…

You’re misunderstanding the relationship between components and styles.

Login box and messages are separate components, but they share padding metrics, border styles, a palette, etc.

Have you used tailwind before?

Re: Learn CSS

#172

I never really "got" the float model for layout, so Grid is a welcome improvement these past few years. That said, this is still missing the one thing I've yet to find in any discussion of CSS. How to appropriately size text. No -- for the 1,000,000th time -- I will not use Modularscale, which feels obtuse to me. Using some formula on a website that someone says works also feels arbitrary. Not to mention that the SAS…

What exactly about sizing text causes issues? Do you mean fluid/responsive sizing? AFAIK, the best modern way to do it is `font-size: clamp(0.75rem, 1rem + 2vw, 3rem)` (the use of rem as well as vw is to not break zooming for accessibility)

Pretty much.

The thing that really made Grid sink in for me was seeing the pseudocode at Grid By Example [1], showing how each of the different constructs work.

[1]: https://gridbyexample.com

Jason Santa Maria's On Web Typography [2] originally included a "worked" example that you could put into a page and pull apart to start building similar things in your own projects. However, before it shipped, this section was dropped.

[2]: https://abookapart.com/products/on-web-typography

With calc and clamp now in the mix, it seems as if we no longer agree that 1rem=16px even if px is probably the most precise screen unit we have.

"Uh, pixels aren't responsive, so let's not even mention them."

It's not the end goal, but it feels like we're throwing away the map which could explain how to reach said goal.

Re: Learn CSS

#173
post #160
post #7

Earlier quoted context omitted.

I think most web users wished web devs understood CSS better (even if they don't know what it is.) I'd be willing to bet half the stuff things like React are used to do could be accomplished much better with a small amount of CSS and probably no javascript at all.

I wish you were right, but this is unfortunately wrong – and it's not because developers don't know CSS well enough, but rather that CSS is just plain not good enough. And ridiculous new features keep being added to it when we still don't even have some of the necessary primitives that should be there. As an example, one of the most basic components I can think of is an accordion. You simply can't make one that works…

The implication here seems to be "when using HTML semantically", because I think everything you're talking about can be done with CSS if you're willing to abuse HTML.

Take this CSS accordion which uses hidden form elements: https://codepen.io/raubaca/pen/PZzpVe

I agree that if you want to use HTML semantically *and* have intuitive UX/UI, you're very limited in what you can do without Javascript, but this isn't *just* a failing of CSS; rather, I think it's due to the design of HTML and CSS historically being to the exclusion of the other, rather than with a symbiotic relationship in mind. Go far enough back into the history of web standards and it kind of makes sense though; HTML and precursors had been in development for years before CSS was standardized

Re: Learn CSS

#174
post #157

I've always wanted to write my own CSS guide, because (in my experience) people are rarely focused on the right thing when they're writing CSS. Developers (especially junior) think that if it looks right, that it is right, and they're done. But CSS is not just specifying how something looks, you are also very much specifying visual behavior , not just appearance. Content is dynamic, layouts change at different breakp…

> Or, using absolute position to, say, anchor a close button to the top right of an element. Sure, the way you did it happened to put it visually in the right spot, but it's not actually in the right spot according to the layout engine because its offset parent is not the element you're trying to anchor it to, so if other content gets put in there eventually, it will be in the wrong spot.

I'm absolutely guilty of this one and would love to know the correct way to do it if you have a resource handy. I generally feel like working with CSS (or ideally Tailwind now) is an uphill battle. In my defense I would also give the container a padding which should (in theory) prevent any of its statically positioned children from overlapping. But as a full-stack developer I often feel like this is the domain of people who spend their entire career focusing on design, and generally when I'm working in this realm its because we don't have one of those people.

Re: Learn CSS

#175
post #160

Earlier quoted context omitted.

I wish you were right, but this is unfortunately wrong – and it's not because developers don't know CSS well enough, but rather that CSS is just plain not good enough. And ridiculous new features keep being added to it when we still don't even have some of the necessary primitives that should be there. As an example, one of the most basic components I can think of is an accordion. You simply can't make one that works…

The implication here seems to be "when using HTML semantically", because I think everything you're talking about can be done with CSS if you're willing to abuse HTML. Take this CSS accordion which uses hidden form elements: https://codepen.io/raubaca/pen/PZzpVe I agree that if you want to use HTML semantically *and* have intuitive UX/UI, you're very limited in what you can do without Javascript, but this isn't *just*…

I appreciate the semantics angle but I don't think it's actually related; semantics are a separate issue.

The reason the animation appears to work in the example you link to doesn't actually have anything to do with the form elements or semantics – rather, it's cheating by animating the `max-height` of the tab content from `0` to `100vh`.

This can be done just as easily without all the form stuff, but it's a bad solution to the accordion animation problem, because (1) it assumes that accordion content will never exceed the height of the viewport (what about on phones in landscape mode? you're only talking a few hundred pixels there), and (2) CSS will ease between the actual minimum and maximum values without regard for where the element's true height actually stops changing, i.e. it will animate from 0 to 100vh in the duration requested even if the height only ended up being like 20px and thus visually stops changing 5% of the way into the transition – so whatever duration and easing you specified isn't actually being rendered in the way that you wanted. If you specified an `ease-out` for example (starts fast, slows down at the end), you'd just get a super fast linear-looking transition that ends much quicker than you planned and never has the slow easing at the end (because CSS is actually still transitioning the `max-height` property which is no longer having any effect on your element that's much shorter than the max-height).

Re: Learn CSS

#176

Earlier quoted context omitted.

That's why it's rem + vw, to prevent accessibility problems

The vw introduces the accessibility bug. Your can add whatever other units to it you like, the issues remain.

What accessibility bug is that? Adding the other unit is specifically so the issues do not remain.

Re: Learn CSS

#177
post #157

I've always wanted to write my own CSS guide, because (in my experience) people are rarely focused on the right thing when they're writing CSS. Developers (especially junior) think that if it looks right, that it is right, and they're done. But CSS is not just specifying how something looks, you are also very much specifying visual behavior , not just appearance. Content is dynamic, layouts change at different breakp…

> Or, using absolute position to, say, anchor a close button to the top right of an element. Sure, the way you did it happened to put it visually in the right spot, but it's not actually in the right spot according to the layout engine because its offset parent is not the element you're trying to anchor it to, so if other content gets put in there eventually, it will be in the wrong spot. I'm absolutely guilty of thi…

Sorry, my description of that one was a bit vague. The error I had in mind wasn't using `position: absolute` to anchor the button, but rather in not thinking about the offset parent.

As an example, if your goal is for the button to appear over the right-side inner box ("hero content") here:

    +-------------------------------------------+
    |+----------+  +---------------------------+|
    || nav      |  | hero                      ||
    ||          |  |                      (x)  ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    |+----------+  +---------------------------+|
    +-------------------------------------------+
...then you should make that button either a direct child of that hero content (and give that container `position: relative` to make it the offset parent), or if that's not semantically acceptable, then add a new container around the hero content which will match its size/position and serve as the button's offset parent.

Otherwise, if you just let the outer container be the offset parent because it happens to place the button in the same spot in the moment, then later when more content gets added to that container, you'll end up with this:

    +-------------------------------------------+
    |+----------+  +---------------------------+|
    || nav      |  | header                    ||
    ||          |  +----------------------(x)--+|
    ||          |  +---------------------------+|
    ||          |  | hero                      ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    ||          |  |                           ||
    |+----------+  +---------------------------+|
    +-------------------------------------------+

...where the button is no longer over the correct box, because it was never anchored to it correctly in the first place (instead, it was anchored to that outermost container).

Re: Learn CSS

#178
post #177

Earlier quoted context omitted.

> Or, using absolute position to, say, anchor a close button to the top right of an element. Sure, the way you did it happened to put it visually in the right spot, but it's not actually in the right spot according to the layout engine because its offset parent is not the element you're trying to anchor it to, so if other content gets put in there eventually, it will be in the wrong spot. I'm absolutely guilty of thi…

Sorry, my description of that one was a bit vague. The error I had in mind wasn't using `position: absolute` to anchor the button, but rather in not thinking about the offset parent. As an example, if your goal is for the button to appear over the right-side inner box ("hero content") here: +-------------------------------------------+ |+----------+ +---------------------------+| || nav | | hero || || | | (x) || || |…

Ahh OK, interesting. That seems like more of an HTML issue than a CSS one (putting the close button element outside of the container element which it's associated with). I'll carry on doing things the way I already do then.

Thanks for the detailed response

Re: Learn CSS

#180
post #33

Looks great! Small pet peeve regarding tutorials: When learning a new technology I don't care about the headaches people had 20 years ago. My first concern is how I use the technology and what it can do for me. The section about layout starts with: " In the early days of the web, designs more complex than a simple document were laid out with elements. Separating HTML from visual styles was made easier when CSS was wi…

Totally disagree. In a technology with a long history, especially one that never breaks backwards-compatibility, a whole lot of things seem nonsensical without context. And this isn't just relevant for apologetic purposes: seeing and internalizing the patterns and the internal logic often requires that background knowledge.

Think about when you're learning to work on a legacy system. You (hopefully) don't just learn the current state of the system in a vacuum. You go through and learn the history of decisions and constraints that got it there, the layer upon layer of changes that resulted in the end result in front of you.

Post reply on HN