ProgrammerHumor

cssIsTotallyNormalAndExtremelyNotInsane

[deleted]

Reddit

Discussion

Eva-Rosalene
:ts::c::bash::powershell:

Yeah, that's what happens when you need to draw complex shape from scratch (because no inbuilt primitives for triangles exist) in a language that usually isn't used for that.

Why not just draw it as path in SVG? Like this. All the shenanigans are in the path's d attribute, which is expected to have data that isn't easily human-readable and all the code around it is normal HTML and CSS without anything wonky.

Edit: added example.

5 hours ago
viktorv9

just use SVG as a mask if you really want to get fancy with the content of the triangle

4 hours ago
[deleted]

[deleted]

5 hours ago
HomieMorphic

It doesn't.

You're having trouble tying your shoelaces with a gun and then claiming that guns are hard to use when yours shoots you in the foot.

4 hours ago
[deleted]

[deleted]

4 hours ago
HomieMorphic

This bait isn't fresh, I'm not taking it. 😤

4 hours ago
[deleted]

[deleted]

4 hours ago
mario73760002

Well, maybe you can code the next GUI Framework with your amazing back end skills

4 hours ago
[deleted]

[deleted]

4 hours ago
H34DSH07

I'll take the wager that you won't be able to do half the things you can do with CSS in your new framework any day.

The "insane crap" is not actually insane if you understand why it's there and how it works. Just like in C++, there are a million different ways to do the same thing, and some are equally insane to the stuff you can do in CSS.

3 hours ago
wgr-aw

Now try drawing a triangle with a rounded corner in Assembly

5 hours ago
xgabipandax

If we are using BIOS routines, then we need to switch to mode 13h and then create a function like

putpixel:
mov cx,320
mul cx; multiply AX by 320 (cx value)
add ax,bx ; and add X
mov di,ax
mov [es:di],dl
ret

then we can set ax with Y coord, bx with X

With a bit of math we can determine which pixel must be drawn to form a triangle

4 hours ago
UristMcMagma
:ts:

Now try making a triangle with rounded edges out of a wooden block and see how much work it takes.

4 hours ago
ChalkyChalkson

Same as the top comment here - draw an svg and put into the appropriate tool.

4 hours ago
prehensilemullet

plugs in react-router

4 hours ago
Embarrassed-Stop6907

there are a lot of cases to make why CSS sucks and is overly complicated

this isn't one of them

4 hours ago
hrvbrs
:js::ts:

CSS is designed for styling elements in a document, not creating new elements. If you want a rounded triangle, use an <img>, <svg>, or <canvas>

4 hours ago
ezhikov

So, you ask a language that exists to make rectangles and text inside rectangles pretty to make a triangle out of said rectangle, and don't like that it takes a bit of effort? Besides, it's pretty readable what is happening. And there are easier ways to do it, for example using ForeignElement interface of HTML to insert proper SVG image.

5 hours ago
[deleted]

[deleted]

5 hours ago
Eva-Rosalene
:ts::c::bash::powershell:

If I give you ANY vector image serialized in whatever textual representation (like SVG), would you be able to tell me what's in there? Yeah, that's how graphics usually work. But what this code does is obvious: it defines mask and clipping path. What shape? Yeah, let's render and see.

4 hours ago
[deleted]

[deleted]

4 hours ago
Eva-Rosalene
:ts::c::bash::powershell:

I can easily tell the CSS that renders a rounded rectangle without having to render it to see what it actually does

Yes, because it is what CSS is mostly for: rectangular stuff laid out in other rectangular stuff.

Triangles could just as easily be part of CSS's vocabulary

Why? What's the reason for that? There is already a tool to draw triangles, it's called SVG.

4 hours ago
[deleted]

[deleted]

4 hours ago
Eva-Rosalene
:ts::c::bash::powershell:

Because modern designs are full of triangles and other odd shapes, and when you stack them up the CSS ends up looking like Oompa Loompa's barf?

No, I just don't use CSS when I need triangular (or other polygonal) shapes. Again, SVGs exist.

Maybe you work with heavenly CSS codebases that have 0 hacky things in them. Some of us ain't that lucky.

We have a shitton of hacks, some of them because of CSS limitations, but mostly because devs (me included) were too hurried to deliver things. Still, none of them are there to draw what arguably is vector graphics.

4 hours ago
[deleted]

[deleted]

4 hours ago
Eva-Rosalene
:ts::c::bash::powershell:

No, I mention SVGs because they are THE right tool to draw vector graphics on web pages.

Most front enders will gravitate towards pure CSS solutions because they're usually the right call.

No, whenever I need to draw some graphics that designers came up with I just export node from figma as SVG and call it a day. Everyone else on my team does that as well.

They have their uses, but they also have their own problems and many, many downsides. That's why hacks such as the one in the code above exist to begin with.

Can you elaborate, what were you trying to achieve with that piece of CSS that would be impossible with SVGs? To put HTML stuff inside triangle? I am yet to encounter that use case in the wild.

4 hours ago
[deleted]

[deleted]

4 hours ago
ezhikov

Of course not. Not only I'm not as proficient in cutting edge CSS, I also support browsers where this doesn't work (no trigonometric functions and no mask property), so this thing is absolutely useless to me in my work. I am also not good at math, so I would definitely fail to code such thing myself (well, maybe I'd manage, but it would take A LOT of time).

And yes, it's complex (I never said it wasn't), but it is indeed readable and possible to quickly understand what different parts do and how they affect our rectangle. It's even possible to do small refactoring and move gradients to custom properties with nice names for better readability.

4 hours ago
ClipboardCopyPaste
:js::cs:

Everything's a box

5 hours ago
patiofurnature

Why wouldn’t you just display it as an image? Use CSS to center it or add padding or whatever.

4 hours ago
[deleted]

[deleted]

4 hours ago
patiofurnature

Maybe you do. How does that change anything?

4 hours ago
PunithR

Yeah, we can use it as a background image.

4 hours ago
swyrl
:cs::gd::rust::js:

There's this wonderful css property called mask-image(link) which you can use to create arbitrary content clipped to an image.

3 hours ago
peterlinddk

Why is it "humor" to now know which tool to use for which task?

Will it also be "programmer humor" to post an image of someone trying to write a thesis in Microsoft Paint, and complaining about how hard it is?

3 hours ago
BarneyChampaign

I don't know. I'd love some kind of verified, "adult swim" programmerHumor subreddit that weeds out student and junior commentary.

3 hours ago
Luneriazz

thats why SVG exist

4 hours ago
conabegame1
:cs::unity::py:

At this point I’m just using an SVG

4 hours ago
XHelperZ

SVG's clearly are illegal i tell you hwat

4 hours ago
Purraxxus
:js:

Svg.

But what if i want to use content inside it?

Still svg.

But what if i want to animate certain parts.

Still svg.

But what if i want to apply styles to certain parts?

Still svg.

3 hours ago
BarneyChampaign

You might as well make a post complaining that your car doesn't fit on train tracks.

Another junior within 24 hours dragging CSS because they don't understand it or, more importantly, when to use the correct tools for the job.

Custom, scalable graphics are easily and should be rendered with the right tool for the job - SVG, not a literal -> box <- model.

3 hours ago
XKeyscore666

It’s like CSS looked at Tikz and said ā€œhow can we make this less intuitiveā€

4 hours ago