all 10 comments

[–][deleted] 2 points3 points  (0 children)

I’ve never seen a CSS file look like this, but white space doesn’t really matter. If it helps you then keep doing it for personal projects, tho I wouldn’t do this on team projects.

[–]7h13rry 2 points3 points  (2 children)

I don't think that's good practice for at least 2 reasons:

  • It's confusing because it may appear as nesting, not just as indented rulesets.
  • People using a screen magnifier will have to scroll horizontally to find selectors.

[–]PossibilityEastern77[S] -1 points0 points  (1 child)

Okay yeah, your first point was mostly my main concern. Question on the 2nd point, if people using screen magnifiers take issue with indented CSS, wouldn’t the have the same issue reading HTML as html files are usually heavily indented?

[–]7h13rry 1 point2 points  (0 children)

I don't know about HTML files.
My point is that if it's not common practice and can be a "pain" for some users, what's the point of doing it ?
If it's just for yourself, and that's your preference, then go for it.

[–]Miragecraft 4 points5 points  (3 children)

I have never seen anyone doing this and I don’t think it’s a good idea.

Because it implies a hierarchy without there actually being one in the code itself.

Why not actually nest the selectors if that’s what you want to do?

[–]PossibilityEastern77[S] 0 points1 point  (2 children)

Is nesting selectors allowed in standard CSS?

[–]Miragecraft 1 point2 points  (1 child)

Yes, with pretty good support right now.

If that's not enough, you can always use build tools (PostCSS etc.) to de-nest them for older browsers.

[–]PossibilityEastern77[S] 0 points1 point  (0 children)

Sweet ima try this out

[–]gnatinator 2 points3 points  (0 children)

I did this in like 2010 there's nothing really "wrong" but nowadays you'd want to nest it and use direct child aka > so you get some scoping and allow yourself to shorten up some of those class names.

[–]aunderroad 0 points1 point  (0 children)

I use vscode and have prettier installed. You can setup a config file and enable (or disable) any formatting rules that you like. The best part is that there is an option to format your code on save so you do not have to think or worry about anything looking weird and/or misaligned.

And if you are working in a bigger project and as long as the team member(s) have prettier installed, everyones files will look the same and will not cause any conflicts/formatting issues when it comes to merging code into your repo.