DEV Community

Cover image for 3 Cool CSS Tricks to Impress Your Friends at Parties

3 Cool CSS Tricks to Impress Your Friends at Parties

Vitor Paladini on June 23, 2020

Wait, no one does that... But the tricks are still great, I swear. So let's start with an intro: My experience with CSS along all those years has...
Collapse
 
robertotonino profile image
Roberto Tonino

2020 goal: get a date with a girl by showing her these tricks

Collapse
 
bherrero profile image
Borja Herrero

Already updated my Tinder profile. Let's see how it goes 🀞

Collapse
 
madza profile image
Madza

Protip #1: It's easier if you use Tailwind

Collapse
 
rootz491 profile image
Karan Sharma

Nice. I'll definitely try that.

Collapse
 
phantas0s profile image
Matthieu Cneude • Edited

Good tips! Thanks for that!

I wanted a show-on-click (third trick) for my blog, a while ago. My problem was: I wanted multiple show-on-click on one page.

The only solution I found was to give different ID for each hidden block / checkbox. Here's an example, in case somebody wanted to do the same thing: codepen.io/phantas0s/pen/dyGWLEb

Collapse
 
sharpseeer profile image
Aaron Throckmorton

If you nest the input element inside the label you don't need the for attribute anymore and the two are automatically linked. In theory, ymmv.

Collapse
 
phantas0s profile image
Matthieu Cneude

Ooh. That's a good idea. Thanks for that.

Collapse
 
hoshiholiday profile image
Hoshi Holiday

So cool!! Definitely looking forward to more of your articles!!

Collapse
 
vtrpldn profile image
Vitor Paladini

Thanks, Hoshi! You have know idea how this feedback made me happy πŸ˜„πŸ˜„πŸ˜„

I plan on posting something new every Tuesday so stay tuned!

Collapse
 
hoshiholiday profile image
Hoshi Holiday

definitely!!! :)

Collapse
 
aminarria profile image
Amin Arria • Edited

That 3rd trick 🀯

Collapse
 
prkr32 profile image
prkr32

Dumb question: I am trying to repeat the hidden/display divs with different clickable labels, but I can't get it to work properly. Every time you click any of the three labels, the first hidden div appears rather than the div associated with that label. I have tried changing the classes of the hidden divs to .example1, .example2, etc. and it still doesn't work properly. I think I need to change the label id or classes but I'm not sure how to do that...

Thanks so much for these tips! I have been looking for a simple way to display divs on click without JS for a while and this seems like a simple way!

Collapse
 
vtrpldn profile image
Vitor Paladini • Edited

Hey, that was a great question. You are almost right, instead of changing classes you'd need to change the id and the for attribute of each label. Here's an example: codepen.io/vtrpldn/pen/WNrZzvd

Collapse
 
prkr32 profile image
prkr32

Wow, thanks so much! This works because the + example always opens the nearest .example, so we don't have to identify the different .examples by changing their class, right? Just weird to me that the id for the different checkboxes are now unique, but we don't have to change any of the CSS to reflect that uniqueness.

Collapse
 
prkr32 profile image
prkr32 • Edited

Dumb question: I am having a hard time repeating this for a few different hidden divs that display on click. Whenever I click any of the labels, only the first hidden div displays. Not quite sure how to fix it. I have tried making multiple .example classes (.example1, .example2, etc.) and that doesn't work either.

Thanks so much for this article though! I have been looking for an easy way to do trick number 3 without JS for a long time and this is a great find!

Collapse
 
hangindev profile image
Jason Leung πŸ§—β€β™‚οΈπŸ‘¨β€πŸ’»

Thanks for sharing! I use that responsive aspect ratio trick a lot.

Anyway, may I join that party? πŸ™‹β€β™‚οΈ

Collapse
 
ms314006 profile image
Clark

Great article! Thanks for that!
I found out a small typo, the padding-bottom: %56.25; maybe is padding-bottom: 56.25%; right?

Collapse
 
neomodus86 profile image
neomodus86

Nice!

Collapse
 
1isten profile image
STEN

when you use percentage on padding it is always relative to the parent width

Thanks! That rocksπŸš€

Collapse
 
kaisermann profile image
Christian Kaisermann

"Wait, no one does that..."

but... they should....