News for hackers. Stuff that matters.
Re:W3C recommends WebAssembly by danShumway on Friday December 06, 2019 @03:39PM (#21725762)
> because you literally can't build a good looking dropdown with normal HTML.

I want to push back against this in particular, not only because I think it does HTML/CSS a disservice, but because I've maintained codebases that took this approach and they're really bad to work with. You're trading a little bit of CSS annoyance for constant positioning/z-index errors -- and you'll need to update your positions whenever your page scrolls or a component grows... there are just so many ways for this to go wrong, and there's always an edge case that developers miss.

Nothing is absolute, but most of the time the proper way to do something like a custom dropdown selector or tooltip is to semantically group it with the component it's attached to, and then at most absolute-position one element to center it relative to its parent.

  <div class="Input">
    <input class="Input__Field">
    <ul class="Input__Options Input__Options--hidden">
      <li>Option One</li>
      <li>Option Two</li>
    </ul>
  </div>

  .Input { position: relative; }
  .Input__Options { position: absolute; /* etc */ }
  .Input__Options--hidden { display: none; }
I don't like everything about CSS, there are a number of problematic design choices in the language -- particularly specificity. I also wouldn't necessarily be against a new primitive for scoping CSS to specific DOM trees. But annoyances aside, overall CSS is pretty great, and on net the apps I maintain that make heavy use of CSS are easier to maintain and less buggy than the apps I work on that try to use JS code to accomplish the same tasks. Obviously that's anecdotal.

Again, this doesn't mean you can't compose your CSS in JS. But separation of concerns is not for you. The point is to let me as a user override or ignore your styles, and to keep your styles away from your core content. When you spit out HTML and CSS, you are spitting out an application interface.

You're really worried about where you write your CSS, and I couldn't care less. I just want devs to render clean styles that I can work with as a user, and to stop using JS mouseover events to poorly recreate a hover selector.

There are no comments on this comment yet.