TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Defensive CSS

377 pointsby jacobralmost 3 years ago

18 comments

Dan42almost 3 years ago
Ok, the first thing I looked at is &quot;long content&quot; <a href="https:&#x2F;&#x2F;defensivecss.dev&#x2F;tip&#x2F;long-content&#x2F;" rel="nofollow">https:&#x2F;&#x2F;defensivecss.dev&#x2F;tip&#x2F;long-content&#x2F;</a> and here they recommend to just clip it. Because who cares about content right? Who cares if the partial content you display is useless, as long as it looks good. And that&#x27;s the kind of tip everyone here is applauding. I would like to say webdesign is in a sorry state nowawadays, except it was also that way 20 years ago. Maybe this &quot;who cares about the content&quot; attitude is inherent to web designers? Sorry if I sound blasé or cynical, but one gets tired after long enough of this.
评论 #32007298 未加载
评论 #32008731 未加载
评论 #32007906 未加载
评论 #32007099 未加载
评论 #32007141 未加载
评论 #32007239 未加载
评论 #32007948 未加载
partiallyproalmost 3 years ago
Most of these are pure common sense if you are apt with CSS.<p>However, one problem mentioned here is vendor prefix grouping. I&#x27;ve never experienced this problem or seen a grouped prefix ignored by any browser. Autoprefixer doesn&#x27;t even ungroup prefix rules. I even ran a grouped prefix through W3C validator and came away validated, though the article mentions it&#x27;s not W3C compliant.
评论 #32007358 未加载
评论 #32007122 未加载
评论 #32006061 未加载
simonwalmost 3 years ago
Suggestion for the breadcrumb example on this page (and other examples like it): <a href="https:&#x2F;&#x2F;defensivecss.dev&#x2F;tip&#x2F;flexbox-wrapping&#x2F;#breadcrumbs" rel="nofollow">https:&#x2F;&#x2F;defensivecss.dev&#x2F;tip&#x2F;flexbox-wrapping&#x2F;#breadcrumbs</a><p>Show the HTML and CSS for the example in plain text below the example - saves me from firing up the browser inspector tools, which aren&#x27;t available if I&#x27;m browsing on my phone.
flanbiscuitalmost 3 years ago
Previous discussion: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=29504784" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=29504784</a><p>Not the same exact link but same author. Looks like he turned his post into a full-blown site.
thex10almost 3 years ago
I will trust any CSS content from Ahmad Shadeed, I am continually impressed and I&#x27;ve been developing CSS my whole career.
评论 #32007112 未加载
评论 #32009359 未加载
评论 #32005078 未加载
pseudosavantalmost 3 years ago
I figured I would share this CSS variable technique I learned here. Tying DOM events into becoming CSS variables can be very powerful.<p><a href="https:&#x2F;&#x2F;dom-event-to-css-variable.glitch.me&#x2F;" rel="nofollow">https:&#x2F;&#x2F;dom-event-to-css-variable.glitch.me&#x2F;</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;pseudosavant&#x2F;dom-event-to-css-variable.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pseudosavant&#x2F;dom-event-to-css-variable.js</a>
bob1029almost 3 years ago
Wow this is great. I could have <i>really</i> used some of these examples a few days ago.<p>CSS grid combined with media queries feels like cheating to me. Am I missing something big here, or is this all safe to use in 2022?
评论 #32006282 未加载
评论 #32005938 未加载
评论 #32007789 未加载
评论 #32005900 未加载
Bolkanalmost 3 years ago
A good offence is the best defence, which is why I prefer offensive CSS.
评论 #32007162 未加载
Cloudefalmost 3 years ago
As someone who is not very good at UX &#x2F; frontend, and especially CSS, these kind of tips are very good.
Waterluvianalmost 3 years ago
This page needs one sentence at the top that explains what Defensive CSS is. “Future proof interfaces” is far too vague (or maybe I’m not smart!)<p>I went to the “Introduction To” article but it began reading like a cooking recipe story.<p>The page is otherwise very elegant.
spoils19almost 3 years ago
It&#x27;s crazy that there&#x27;s so much extra cruft when it comes to crafting web interfaces when a CLI is most often the most powerful and easiest way to get a job done. Am I just taking crazy pills?
评论 #32008554 未加载
评论 #32006589 未加载
评论 #32006598 未加载
评论 #32006482 未加载
评论 #32006623 未加载
remialmost 3 years ago
Reminds me of the classic CSS book (2005?) by Dan Cederholm: <a href="https:&#x2F;&#x2F;www.amazon.com&#x2F;Bulletproof-Web-Design-flexibility-protecting&#x2F;dp&#x2F;0321808355&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.amazon.com&#x2F;Bulletproof-Web-Design-flexibility-pr...</a>
BiosElementalmost 3 years ago
Really love the togglable examples. It&#x27;s often hard to imagine how a change look and while in a perfect world I&#x27;d have time to make a mockup to test each version, well, it&#x27;s hardly a perfect world so examples are appreciated!
评论 #32009676 未加载
thealistraalmost 3 years ago
Those negative examples don&#x27;t work for me on Safari, I can&#x27;t drag the frame small enough to trigger the bad examples - it seems not to allow it.<p>So tbh the content looks good for me in both bad and defensive cases
correct-me-plzalmost 3 years ago
Hilariously they haven&#x27;t always applied the defences they&#x27;re promoting - in the &quot;Scroll chaining&quot; example the page will scroll if you over-scroll the example
jakearmitagealmost 3 years ago
I constantly struggle with CSS grids when compared to, say, just using Bootstrap. I know Bootstrap comes with a lot of baggage, but the syntactic sugar is just so useful.
评论 #32007817 未加载
mrcartmenesesalmost 3 years ago
Some really nice tips here.
distantsoundsalmost 3 years ago
CSS3 got approved in 2006 and now we are at the point where we have to treat the language like it&#x27;s fighting against us. Quality work the consortium has done in the past 15 years, eh?
评论 #32006413 未加载