11 ms·
Being picky about a CSS reset for fun
- nailer 3y agoPity there’s no discussion of grid/flex by default, especially for someone that dislikes margins. Put grid/flex on most block elements. Spacing between boxes and their children is always handled with padding, spacing between siblings is always handled with gap. Everything else becomes way easier.
- klysm 3y agoSometimes I want more control than gap can provide, especially in grid. Suppose I want different gaps between different columns in a CSS grid - how would I accomplish that?
- mock-possum 3y agoWhat’s stopping you from defining the gaps as individual entries in your template? First column ‘fr’ gap ‘15px’ second column ‘fr’ gap ‘30px’ third column ‘fr’ and now you have three equal columns with two different gaps?
- muspimerol 3y agoThe downside with this approach is that I often want the element itself to define how much space is around it. When you conditionally include elements in a layout, I find margin more expressive and less cumbersome than changing the grid-template-column property of the parent.
- deleted 3y ago[deleted]
- nailer 3y ago> Suppose I want different gaps between different columns in a CSS grid - how would I accomplish that? Good question. That sounds like you have different groups. eg: you're thinking of it as: .items .item1 (thin gap) .item2 (thick gap) .item3 But it's actually: .items .sale (thin gap) .item1 .item2 .regular (thick gap) .item3
- threatofrain 3y agoI've been exploring this idea in my more recent code and so far no regrets. I'd go so far as to say that grid is often the better flexbox because (1) the DSL that allows arbitrary names is so nice for specifying alternative responsive designs and (2) it lowers the temptation to create unnecessary divs for the sole purpose of layout.
- RetiredRichard 3y agoEverything is opinionated, including resets. Give me that warm 2014 feelings again
- danielvaughn 3y agoI didn't realize ShopTalk Show was still going on. I was an avid listener waaay back in the day.
- johnnyworker 3y agoFor me the article link returns a JSON response. Tested in two browsers. Other articles on that site work normally.
- ForkMeOnTinder 3y agoSince the article is about being picky, here's something that stood out: > -moz-text-size-adjust: none; > This makes it so iPhones... Why is a -moz- prefix needed for a Safari workaround?
- faitswulff 3y agoThe linked Kilian article [0] explains that it’s for Firefox on Android devices. [0]: https://kilianvalkhof.com/2022/css-html/your-css-reset-needs-text-size-adjust-probably/ https://kilianvalkhof.com/2022/css-html/your-css-reset-needs...
- qingcharles 3y agoNote that page says that "The New CSS Reset" has this issue, but it doesn't, it was added recently, for better or worse. I did touch base with Kilian about it, but he hasn't updated the article. He might have a newer article, I don't know.
- culi 3y agothe prefixes don't really mean much nowadays. Most browsers will support all other browser prefixes. There are simply CSS problems that haven't been solved by the CSS standard itself. Sometimes different browsers come up with their own solution that is not in the standard (though this rarely happens anymore). In order to prevent "this website looks weird on <SOME_BROWSER>", SOME_BROWSER needs to implement support for it. There are very few prefixed CSS properties that aren't supported by all browsers nowadays. Think of them as stopgap solutions until the actual CSS standard catches up
- sandreas 3y agoI found these four reset options best for my use cases: https://pilabor.com/blog/2021/03/html-and-css-tricks/#normalizecss https://pilabor.com/blog/2021/03/html-and-css-tricks/#normal...
- irrational 3y agoWhat is the difference between a reset.css and a normalize.css? They both seem like they are doing the same or similar things. Is it a naming preference? Is one better than the other? Do some people use both?
- ceetrav 3y agoDifferent browsers provide different default styles. Reset removes these styles while normalize tries to make the default styles consistent between the browsers.
- sedatk 3y agoI wonder how much the style difference among browsers is today. Maybe, we only need a one liner to align all browsers but nobody bothered to check again.
- Klathmon 3y agoThere are a ton of significant differences between browsers, especially when it comes to input elements, and around focus. There are even OS differences between the same browser! This site shows some of the default styles for different elements: https://browserdefaultstyles.com https://browserdefaultstyles.com
- sedatk 3y agoAwesome source, thank you!
- deleted 3y ago[deleted]
- codedokode 3y agoReset removes all default styles, so paragraphs become without margins, lists without bullets, tables without borders etc. Normalize tries to fix default styles so that they look the same in every browser.
- butz 3y agoNice to see the real CSS tricks back.
- c-fe 3y agoIn the past month or so I finally managed to get into web development (using cloudlfare workers/pages, they are amazing), and I tried to do a bottom up approach. I really dont like huge frameworks that you install with a sleek small command but they add 100s of weird files to your repository that you have no idea what they are for and cant really all read. So I started off with just HTML, vanilla js and ofcourse CSS. Now after a weeks of using that stack, Im slowly starting to understand why there is certain software (frameworks, packages) that everyone seems to be using, and I may switch as well. One of the first things I ditched was CSS and I switched to tailwind. Apart from making it easier to make stuff look good, it just generally seems to make building layouts so much easier. Maybe I just did not go enough into CSS, but I can not see myself ever going back to vanilla CSS now that I have started using tailwind, so articles like these I always find interesting as they show experienced people not using tailwind so they probably have some good reasons why they prefer CSS.
- eyelidlessness 3y agoI applaud your pragmatism. And I wish this pragmatic attitude was more common here, it’s refreshing in a sea of negativity whenever anything about web dev is posted. Re: CSS layout. It’s actually just a very big, complex practice to become proficient in. If you’re ever inclined to go back and relearn it, it helps to accept that from the outset. Once you’ve accepted that it’s a fairly involved learning process, the successes should feel more significant and the failures hopefully more temporary. But! Re tailwind: if it’s working for you, and you never feel compelled to drop into lower level styling concerns, that’s fine. Great even. You’re getting stuff done that you want to do, with tooling that addresses your needs! I don’t personally love tailwind, and I much prefer to write styles directly… but it’s obvious tailwind solves this well for you and others who don’t share my preference. Re CSS vis tailwind: probably overly pedantic, but you are still using CSS. You’re just not authoring it directly. I’m only pointing this out because you may find a time when tailwind doesn’t do everything you want/need, and it’ll help to know it isn’t some styling black box. It’s just a very thoroughly robust abstraction around the styles you could write directly if you choose. And if that abstraction, however robust, doesn’t fit your needs, plain CSS is always there to supplement it.
- qingcharles 3y agoWarning that Chrome has an old bug that kills performance on things like * selectors: https://github.com/elad2412/the-new-css-reset/issues/66 https://github.com/elad2412/the-new-css-reset/issues/66
- youngtaff 3y agoIt's not the * selector that's the problem in that case though - it's the `all:unset` declaration
- bornfreddy 3y agoMozilla should use that extensively on MDN to give Google some of its own medicine. Unless of course performance problems of Google's sites on Firefox are just a coincidence...
- codedokode 3y agoCSS resets are bad idea and shouldn't exist. Every time you see paragraphs without margins, or lists without bullets, it is probably a fault of CSS reset.
- contravariant 3y agoNo you see giving users any agency over how your website is displayed is a bug and needs to be fixed. User agents be damned.
- akira2501 3y ago...and by all means, ignore how it looks printed.
- deleted 3y ago[deleted]
- lmm 3y agoCSS resets wouldn't be necessary if browser default styles weren't awful, but here we are. The default browser styling is the worst of all worlds: not enough to make an unstyled page look good (partly the result of the terrible text size inflation trend, which is a whole other rant), but enough to get in the way for a page that's been deliberately styled.
- codedokode 3y agoCSS reset is worse than any default browser style: in browser paragraphs are separated and lists have bullets. With CSS reset, there are no styles at all, and the page looks like unformatted text.
- lmm 3y agoI don't think anyone ever uses a CSS reset on its own, the point is to reset and then put your own style on. Browser default styles aren't really good enough to be usable IMO; yes they have paragraphs but with zero margin and tiny text they're not exactly readable. Twitter Bootstrap is pretty much a bug report against the browser default style. Given that current browser default styles are half-assed at best, I'm sympathetic to the idea that not having a default browser style at all would be better.
- deleted 3y ago[deleted]
- fatih-erikli 3y agoOnce upon a time an interviewer in a job application that I participated was expressed his disappointment when he see that I didn't use css reset in the challenge they sent to me. I'm glad he is disappointed. I feel irritated when the people in tech so picky about the things that has an answer "hmm, yes, probably we should use", "lets not use, not worth it in this case". There was 2 html tags and an svg graph something like that in the page. I suspect he wasn't a tech person either, he was probably reading a google docs about how to interview fe person. I personally don't use reset css and my web pages look ok. There are so many web pages that doesn't use reset css, they look ok. I also don't like when people are being picky about things for fun. This is a job that people take seriously.
- erikpukinskis 3y agoSomewhat off topic, but it annoys me that CSS resets kill the margins on p, h1, h2, and ul. As well as the list-style. I basically don’t use those elements for UI components, and in the rare cases where I would want to, I could just do a one-off to override them. Or, more likely I’d just do something like <div role="heading" aria-level="1"> I find in applications you eventually need some little places where you have some basic document styles: paragraphs, headings, bullets, and it’s nice to be able to use those basic semantic tags for that stuff.
- bdlowery 3y agoBecause collapsing margins are annoying. Doing this removes that. All you have to do is just use margin-top or margin-bottom on them.
- wwweston 3y ago> body, h1, h2, h3, h4, p, figure, blockquote, dl, dd { margin: 0; } Why? I mean, I kinda get this on `body`. But I've never understood why people do this on block level elements like paragraphs and headers where default behavior should definitely be margins. Closest I've ever come to a rationale is so that you'll see the unset margins and intentionally specify them into whatever design systems you're using. But even that doesn't really make sense: if you've got an off-the-shelf design system, it will do that job, you don't need your reset to do it. If you've got the time/inclination to DIY, you are almost certainly the kind of person who will pay attention to this. And if you're neither of those, your reset should do something sane by default. Resets should be about standardizing sane cross-browser defaults for quasi-naked HTML. This kind of behavior goes beyond that into nuking sane behavior for naked HTML. Why?
- deleted 3y ago[deleted]
- bornfreddy 3y agoTo play the devil's advocate: so that you notice that something is amiss and you fix it. The problem with margins on these elements (at least, this used to be true - not sure if this is fixed nowadays) is that every browser implements its own defaults. Some of them might be suitable, but that will only mean that if the designer doesn't set them, these settings will be off in other browsers. So someone who cares might just as well set everything to 0 and then set as needed. Also, less likely that some margin will be set where 0 is appropriate. On the other hand not much is lost with this. If css is ignored, cool. If not, other settings will fix layout as needed.
- fyrn_ 3y agoThere are two schools of thought for CSS resets. 1. Minimize differences between browsers, keep some things like default padding, and styling where it makes sense 2. Nuke everything, standarize box-sizing, etc.. And I lied, there are also some that are more in between, but that's the jist. The main argument for #1 is that it's closer to vanilla and lighter weight. The main argument for #2 is that of you're making a comprehensive style, it's nicer to not have to worry about how for input elements have wierd legacy behavior, or to have to have a list of non standard box-sizing elements and a bunch of other weird legacy style anachronisms open all the time. I personally, and I've seen this happen to others started out in camp #1 and eventually transitioned to camp #2 after I realized just how weird some stuff is. It definitely didn't mame sense to me until I had a lot of CSS experience.
- paradox460 3y agoI've been using a postcss module that implements the reset property. It's pretty nice.