Live data from Hacker News

CSS Container Queries in Web Components

mxb.dev

51–60 of 78 posts

Re: CSS Container Queries in Web Components

#51

Earlier quoted context omitted.

I remember the dumpster-fire days too. The thing that I can't understand is, why did it take SO LONG to get useable, proper, and intuitive CSS-based layout on web-pages? I mean, we've had all kinds of rock-solid mechanisms for layout in desktop applications since the dawn of GUI's in the NINETEEN EIGHTIES. Meanwhile, in CSS, people had resort to HTML tables up until sometime in the early naughts, when AWFUL, counteri…

> The thing that I can't understand is, why did it take SO LONG to get useable, proper, and intuitive CSS-based layout on web-pages? Many reasons: - HTML and CSS are not designed for anything complex. HTML and CSS at their core are only meant to display a static page of text and some images in a single rendering pass on a computer from 1990s. - Many decisions in CSS (especially early CSS) are one-off solutions that m…

> HTML and CSS are not designed for anything complex.

Yeah, I believe you, I can see how that would have been the thinking back in the 90's. But there started to be significant web applications in the early 2000's.

It's all water under the bridge now, but what if there had been more "throwing away" (deprecation) of the bad stuff and less mitigation with the whims of browser implementors? I feel like we would be in a better position today.

What if the W3C had taken a more standards-based approach with hard PASS/FAIL requirements on styling/layout/semantics rather than "recommendations" that browser implementors have always taken as optional and subject to interpretation?

Re: CSS Container Queries in Web Components

#52
post #48

Earlier quoted context omitted.

Every time I hear someone complain about CSS I just know they've never used it in the IE6/7 days. Good lord, the amount of hacks, shims, fallbacks, polyfill, obscure stuff you had to do to make it work in IE6, IE7, and my absolute favourite(!) the IE7 compatibility mode which was like IE6 but not quite! Ever since the wide adoption of stuff like flexbox and grid I haven't dared to complain about not getting stuff to…

My favorite obscure thing: you sometimes had to add the zoom:1 CSS declaration so the element would "have layout", Whatever that meant, so it behaved the way you wanted. You also had the various filter: progid:DX… declarations to make things that came with other browsers work on IE using DirectX directives. This would, by the way, break the CSS syntax because of the colon in the value, but fortunately parsers of othe…

The box-sizing property is actually very useful for when you want to reserve space in a percentage sized element with different sizing units.

For example (in SASS CSS):

  .container {
    $footer-size: 2em;
    box-sizing: border-box;
    height: 100%;
    padding-bottom: $footer-size;

    .footer {
      position: absolute;
      bottom: 0
      left: 0;
      height: $footer-size;
    }
  }




Otherwise, one would have to use calc() which isn't supported in older browsers.

Re: CSS Container Queries in Web Components

#53
post #4

I keep having mixed feelings about web components... Why can't we have templates, custom elements and scoped CSS without JS?

There's no generic HTML import function yet. Right now you can only have a page pull in javascript (through a script tag or ES module import) or CSS files, but critically not component HTML files. So it's hard to have a component defined by HTML and CSS that can be shared and imported in other pages. There's no "grab this HTML page and give me the DOM to insert/clone/use how I please" in pure HTML. The closest thing…

HTML Imports did exist and was the general authoring idea for web components, but it didn't work exactly as you described and Apple and Mozilla shut it down. Polymer had to release a new version that was JS focused and caused a huge painful migration for users.

Re: CSS Container Queries in Web Components

#54

Earlier quoted context omitted.

I am not very familiar with the technology. Under current standards, is it possible to choose to write a web component that does not have any JS, it just uses CSS to take advantage of these things?

No, a web component by definition must be a class that inherits from a HTMLElement base class and implement some basic rendering functions. In addition you must make the browser aware of the component by calling a CustomElementRegistry.define function with your class and the desired component name. So at a minimum there's about 5-10 lines of boilerplate JS necessary to define and register a basic component.

You described a Custom Element a Web Component is a branding phrase for component that uses the four following specs:

* Custom Elements

* Shadow DOM (seems to be optional in practice)

* HTML Template Elements

* ES Modules (formerly HTML Imports)

Re: CSS Container Queries in Web Components

#55
post #29

Earlier quoted context omitted.

Why server side rendering? Content that needs rendering just put in the tree and target a slot. My perception was this is the best practice. I haven't used the lit included intl translation and am curious if and how these concerns work.

Doesn’t that still require JavaScript? As I understand it (and I might not; I don’t have servers to do SSR) people want SSR for two reasons. a) To allow users that don’t have JavaScript for some reason to at get good UX, and b) to prevent the styles from kicking in after the initial render. There are ways to author your components in a way that fixes (b), but I’m not aware of any technique other then SSR that will fi…

I don't think anyone is really targeting JS-less users. It's mostly for faster first renders and the examples of JS-less is to typically show something has been SSR'd and not yet hydrated / not loading anything that isn't needed for first render.

Re: CSS Container Queries in Web Components

#56
post #48

Earlier quoted context omitted.

My favorite obscure thing: you sometimes had to add the zoom:1 CSS declaration so the element would "have layout", Whatever that meant, so it behaved the way you wanted. You also had the various filter: progid:DX… declarations to make things that came with other browsers work on IE using DirectX directives. This would, by the way, break the CSS syntax because of the colon in the value, but fortunately parsers of othe…

The box-sizing property is actually very useful for when you want to reserve space in a percentage sized element with different sizing units. For example (in SASS CSS): .container { $footer-size: 2em; box-sizing: border-box; height: 100%; padding-bottom: $footer-size; .footer { position: absolute; bottom: 0 left: 0; height: $footer-size; } } Otherwise, one would have to use calc() which isn't supported in older brows…

Absolutely. By the way, it seems many frontend developers generally prefer box-sizing:border-box, and Bootstrap sets it for all elements by default.

Which can be a little disturbing when you don't know it, work on a project that includes bootstrap and you expect content-box. Fortunately, browser dev tools are good at telling you what is going on.

Re: CSS Container Queries in Web Components

#57
post #10

Earlier quoted context omitted.

Do you know what the quirk is called? Is there a blogpost detailing this strange method? Is there any mention of it in the web standards sites?

I don't believe it's a quirk. Browsers are supposed treat tags they don't recognize basically the same as a (or some other reasonable default presentation). It's intentionally designed that way for forward compatibility. We rely on this behavior when we provide some content inside an tag for browsers that don't support it.

HTMLUnknownElement

https://developer.mozilla.org/en-US/docs/Web/API/HTMLUnknown...

Re: CSS Container Queries in Web Components

#58
post #56

Earlier quoted context omitted.

The box-sizing property is actually very useful for when you want to reserve space in a percentage sized element with different sizing units. For example (in SASS CSS): .container { $footer-size: 2em; box-sizing: border-box; height: 100%; padding-bottom: $footer-size; .footer { position: absolute; bottom: 0 left: 0; height: $footer-size; } } Otherwise, one would have to use calc() which isn't supported in older brows…

Absolutely. By the way, it seems many frontend developers generally prefer box-sizing:border-box, and Bootstrap sets it for all elements by default. Which can be a little disturbing when you don't know it, work on a project that includes bootstrap and you expect content-box. Fortunately, browser dev tools are good at telling you what is going on.

Thanks, I wasn't aware of this disparity. I handwrite my CSS, been doing it for 21 years now.

If I was to use Bootstrap or Tailwind, I'd likely use @extend and @include to compose my own classes.

A long time ago, I read an article that stated, with authority, that Bootstrap was being misused. That class names like "font-weight-light mt-4 text-white" should instead have been replaced with "subtitle" with CSS:

  .subtitle {
    @extend .font-weight-light, .mt-4, .text-white
  }
The article resonated with me. This approach avoids mixing HTML/CSS concerns and also avoids polluting the CSS namespace. Even if tree shaking and css pruning is applied, I believe this approach would win out in performance for having less classes. I would be wrong if there are tools that will run through HTML and CSS and transform the long bootstrap class attributes into consolidated, shared classes.

Global classes, like in Bootstrap, also violate web component encapsulation.

Global CSS classes are kind of like global variables in programming languages (like PHP.) Sure, they work and used to be common, but we've since moved on to closures and scope containment for performance and reliability.

Re: CSS Container Queries in Web Components

#59
post #2

I've picked up css after ~5 years and I can't believe how far it's come. Flexbox, grid, `clamp()`, content queries, etc. It's a complete different experience now compared to the days of css hacks.

I was explaining to a much younger colleague the hoops we used to have to jump through to get rounded corners and drop shadows. He honestly thought I was lying when I told him it involved exporting sliced-up images from Fireworks and placing them in tables. Now it's two lines of CSS.

LOL fireworks! I had forgotten about that.

Re: CSS Container Queries in Web Components

#60
post #56

Earlier quoted context omitted.

Absolutely. By the way, it seems many frontend developers generally prefer box-sizing:border-box, and Bootstrap sets it for all elements by default. Which can be a little disturbing when you don't know it, work on a project that includes bootstrap and you expect content-box. Fortunately, browser dev tools are good at telling you what is going on.

Thanks, I wasn't aware of this disparity. I handwrite my CSS, been doing it for 21 years now. If I was to use Bootstrap or Tailwind, I'd likely use @extend and @include to compose my own classes. A long time ago, I read an article that stated, with authority, that Bootstrap was being misused. That class names like "font-weight-light mt-4 text-white" should instead have been replaced with "subtitle" with CSS: .subtitl…

I thought this when I first encountered Bootstrap, and it is still my opinion today. I think class names should convey intent and meaning, not the look. I'm glad someone wrote on this.

People seem to like bootstrap, but it seems with bootstrap, not only you have to master CSS, but also bootstrap, while without it you only need to master CSS. I'm also used to hand write CSS and I'm a bit at loss when I need to use such CSS frameworks. It seems that some people find it easier to deal with CSS with Bootstrap (including people who don't really like CSS), but haven't really understood this to this day. I know the default behavior of a web page pretty well, but as soon as bootstrap is there, this knowledge is partly gone and my assumptions are broken. It just makes my life a bit harder.

This would be fixed by learning Bootstrap properly but I just don't see the appeal, especially that I noticed defaults that I don't like (the sizing for headings for instance). It does not seem to solve a problem I have. It does provide interesting components like popovers though.

Post reply on HN