34
Nov 18 '21
Better than a client demanding that header to be half a pixel lower lol
7
Nov 18 '21
[removed] — view removed comment
16
Nov 18 '21
I showed him two versions on with it a pixel lower and he wanted it to be exactly in the middle
34
u/glydy Nov 18 '21
Typing numbers? Not having a unit variable and multiplying/dividing? Disgusting
6
u/i_post_gibberish Nov 18 '21
I’m probably barking up the wrong tree, but isn’t that pointless when you have a decent editor and/or preprocessor? I would’ve said it was better to have only hardcoded values (not necessarily in px) in the final code for performance and compatibility reasons, and to handle standardization and stuff with Sass or an editor extension or something.
4
u/DeepSpaceGalileo Nov 18 '21
I try to avoid magic numbers in code
1
u/i_post_gibberish Nov 18 '21
To clarify, what I do is use Sass variables and functions. Like, say, for media queries, my code just runs through a for loop of 200px increments of width and uses various expressions based on those to set the widths/heights/etc of stuff in rem. The end result is a repetitive mess of hardcoded values, but I can still tweak the layout without manually changing every media query. I’m not suggesting that’s a best practice or anything, since I’m just a hobbyist and couldn’t care less if my code scales (since I’ll never need to scale it).
3
u/huebomont Nov 18 '21
using actual CSS variables gives you much more flexibility including being able to adjust spacing and proportions on the fly in response to user settings. Plus it makes it clearer what the code does and why the result is what it is.
1
u/i_post_gibberish Nov 19 '21 edited Nov 19 '21
Really? You mean there’s a way to change the value of a variable after the page loads? I know it’s trivial to achieve the same result in JS, but I’ve always wished there was a way to do it in CSS but was under the impression that there wasn’t.
1
u/huebomont Nov 19 '21
you’d likely need JS to change the variable unless it’s in response to a media query or pseudo-class of some kind, but pre-evaluating sass variables doesn’t let you do that at all.
1
u/tyzzex May 03 '22
Technically, yes. Can have animation keyframes that change CSS variable, media queries or count (can be combined with a calc). But not what I think you meant, still might fit a few scenarios. In JS you can change css variables with el.setAttribute("--name", "20px").
2
u/White_Tragic Nov 18 '21
Can you share an example of what you're talking about?
13
u/i_got_dressed_today Nov 18 '21
--default-spacing: 8px;
margin-top: calc(var(--default-spacing) * 4));
7
5
-5
u/bheklilr Nov 18 '21
Unless they have to support ie11
9
u/i_got_dressed_today Nov 18 '21
The question was an example, not an example that you can use in old browsers.
6
u/bheklilr Nov 18 '21
Yeah, I know. I just wanted to complain and be sad because I don't get to use css variables.
6
u/i_got_dressed_today Nov 18 '21
I'm sorry. As someone who has a vivid memory of having to support IE5.5 for Mac, I feel your pain.
2
u/glydy Nov 18 '21
SASS will compile to plain CSS that is compatible down to IE8, at least in terms of using variables and math. We supported it for a bit too long but never had spacing issues
17
15
u/isthisneeded29 Nov 18 '21
Why are they using absolute values??
30
u/theXpanther Nov 18 '21
It's that I have to put 19px (ugly number) instead of 1 REM (beautiful number)
6
1
2
7
3
1
u/serverlessmom Nov 18 '21
Wow things are really heating up in the CSS fandom ;). Thank you all for the hilarious and enlightening posts!
2
2
2
2
1
1
1
41
u/jacobtcoleman Nov 18 '21
but 19 is prime