r/css • • Nov 18 '21

Cursed CSS: Only odd numbers

Post image
895 Upvotes

41 comments sorted by

41

u/jacobtcoleman Nov 18 '21

but 19 is prime

17

u/flojoho Nov 18 '21

Even worse!

8

u/Notakas Nov 18 '21

But it's anxiety inducing

34

u/[deleted] Nov 18 '21

Better than a client demanding that header to be half a pixel lower lol

7

u/[deleted] Nov 18 '21

[removed] — view removed comment

16

u/[deleted] 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

u/eatenbyalion Nov 18 '21

Some new contributor will divide by 6.5 I promise you.

5

u/White_Tragic Nov 18 '21

Thanks for that.

-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

u/uxfirst Nov 18 '21

I've never heard of a legitimate ux designer who doesn't use 8px grid

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

u/isthisneeded29 Nov 18 '21

Exactly relative values

1

u/Autistic_idiot735 Nov 04 '25

I’m like SUPER new to CSS can you explain what REM is please?

2

u/ju5tu5 Nov 18 '21

Came here to say this!

7

u/eisolo Nov 18 '21

rem 4 eva

7

u/Kthulu666 Nov 18 '21

2rem vs 1.9rem

3

u/poopio Nov 19 '21

2rem vs 1.8499em

3

u/Jeph125 Nov 18 '21

These two play ping pong in my head

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

u/poopio Nov 19 '21

Who would have thought people'd like a css post in /r/css?

2

u/[deleted] Nov 18 '21

I only use primes.

2

u/The_Codepoet Nov 18 '21

I thought I was alone haha

1

u/llewynparadise Nov 19 '21

i exclusively use prime numbers in my css

we are not the same

1

u/jcunews1 Nov 20 '21

I bet that developer code like this also.

result = value + 20 -1;

1

u/tyzzex May 03 '22

I felt bad giving the 521st upvote when it was an even 520.