TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How I'm writing CSS in 2024

68 点作者 leerob超过 1 年前

8 条评论

recursive超过 1 年前
I kind of prefer it the old, allegedly bad way. I just write selectors and rules in my css files. I use approximately &quot;semantic&quot; selectors, but I&#x27;m not religious about it. Everything seems to work pretty good.<p>I haven&#x27;t had to scale this to a mega-app, but most CSS doesn&#x27;t.
评论 #38908782 未加载
davidy123超过 1 年前
I was trying to find a definition for &quot;css modules,&quot; which the author links but the link is self-referential. I followed a few links, and I came across this: &quot;.jsx files support both global CSS and CSS Modules. To enable the latter, use the .module.css extension (or .module.scss&#x2F;.module.sass if using Sass).&quot;<p>which I would call x-dimensional rabbit holes.<p>I think I&#x27;ll keep on with web components and the shadow DOM.
评论 #38910601 未加载
chrismorgan超过 1 年前
&gt; <i>Cross-browser support for nesting, :has(), container queries, and more¹</i><p>&gt; <i>¹: More: linear() easing, subgrid, dynamic viewport units, color spaces, and @layer.</i><p>Of these: @layer has broad support from March 2022, dynamic viewport units from December 2022, but the rest have less than a year (a couple less than a <i>month</i>). You shouldn’t <i>depend</i> on any of these yet for general web content. It’s pleasant to find that no single browser is lagging behind: Chromium, Safari and Firefox are all first to implement at least one of these features by more than a year, and all last to implement at least one of these features.<p>(Also, a correction: the nesting link should be <a href="https:&#x2F;&#x2F;caniuse.com&#x2F;css-nesting" rel="nofollow">https:&#x2F;&#x2F;caniuse.com&#x2F;css-nesting</a>.)<p>—⁂—<p>&gt; <i>1. Stylesheets should load as fast as possible (small file sizes)</i><p>&gt; <i>2. Stylesheets should not re-download unless changed (proper caching headers)</i><p>There’s a fascinating contradiction in the midst of these two: inlining CSS (as in, from a &lt;link rel=stylesheet&gt; to a &lt;style&gt;) is unreasonably good for performance up to surprisingly large file sizes (I haven’t tried to get good numbers, but reckon it’s comfortably into the tens of kilobytes <i>transferred</i>).<p>If you have the ability to conveniently do it, try inlining all CSS files always, and get a feel for the performance differences. The results may surprise you.<p>&gt; <i>4. Fonts should load as fast as possible and minimize layout shift</i><p>I would remind people that “as fast <i>as possible</i>” means just don’t use them. I would also remind <i>users</i> that you can disable web fonts: my experience is that the fallout is slight, and the advantages due to consistency significant.<p>—⁂—<p>&gt; <i>Specify target browsers (browserslist) and have syntax lowering to compile modern CSS features to work with those browsers</i><p>Just remember that this is primarily about <i>syntax</i> features like nesting selectors or rgb(<i>r g b &#x2F; a</i>) instead of rgba(<i>r</i>, <i>g</i>, <i>b</i>, <i>a</i>). Of runtime features, it can only help with a few, e.g. adding RGB approximations for wide gamut colours, or <i>kinda</i> supporting logical properties like margin-inline. Things like :has(), container queries and subgrid, it can’t help you with.
angra_mainyu超过 1 年前
It&#x27;s incredible how CSS has almost become SCSS (barring some features like loops, placeholders, and mixins).
评论 #38910275 未加载
katspaugh超过 1 年前
I second the author’s recommendation for CSS modules. However<p>&gt; And because the styling code lives outside your TypeScript files, you don&#x27;t get type safety and autocompletion.<p>You actually do, there’s a TypeScript plugin from CSS modules that generates types for your CSS classes (at least).
评论 #38909913 未加载
评论 #38914169 未加载
blabla1224超过 1 年前
This page crashes my safari and Chrome tab instances on my iPhone
评论 #38907161 未加载
debesyla超过 1 年前
How I write CSS in 2024: Tailwind.
threatofrain超过 1 年前
One last reason to use Sass would be parameterized media queries.
评论 #38906375 未加载
评论 #38906245 未加载
评论 #38909266 未加载