DEV Community

Rupak Dey
Rupak Dey

Posted on Edited on

5 CSS Tricks Nobody Tells You!

1. Center Anything

Using Flexbox, Align Items & Justify Content

.center {
   display: flex;
   align-items: center;
   justify-content: center;
}
✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด ✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด

Edit :-

Note:- '.center' should be applied to the parent of the element to be aligned.
Another way to implement suggested by @mrdanielschwarz >> here

2. Smooth Scrolling

No JS. Only one HTML property

html {
   scroll-behavior: smooth;
}
✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด ✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด

3. Change Cursor To An Image

Whenever the mouse hovers over the particular division, the cursor will change to the specified image

.change__cursor {
   cursor: url('path/to/the/image.jpg'), auto;
}
✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด ✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด

4. Add Shadow To Transparent Image

No more box shadows

.drop-shadow {
   filter: drop-shadow(3px 6px 9px #636161);
}
✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด ✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด

5. Truncate Text

The below property helps you truncate the text to the specified number of lines

Edit:-

Appended the additional properties as suggested by @pustelto >> here

p {
   -webkit-box-orient: vertical; 
   -webkit-line-clamp: 4; 
   display: -webkit-box; 
   overflow: hidden;
}
✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด ✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด



Do try them!


Have knowledge of other tricks that can help reduce CSS coding time? Feel free to share in the comment section below!


Support me : Buy me a coffee!

Top comments (9)

✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด
 
pustelto profile image
Tomas Pustelnik • • Edited

The line trunctation in your 5th tip won't work like this. You have to add few more properties, in order for it to work properly:

  -webkit-box-orient: vertical; 
  -webkit-line-clamp: 4; 
  display: -webkit-box; 
  overflow: hidden;
✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด ✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด
✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด
 
deyrupak profile image
Rupak Dey •

Thank you!
I've added this in the edit.

✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด
 
zaxwebs profile image
Zack Webster •

Learned about the custom cursor here, thank you!

✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด
 
deyrupak profile image
Rupak Dey •

That's great to know! Drop a follow for more :D

✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด
 
noobsdev profile image
Om_P •

Good one!

✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด
 
deyrupak profile image
Rupak Dey •

Thank You!

✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด
 
shanah profile image
Shana •

Wooo thanks!

✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด
 
deyrupak profile image
Rupak Dey •

You're welcome :D

✨ อัปเดตล่าสุด: deyrupak/ css tricks nobody tells you nmb - สรุปดราม่าล่าสุด
 
deyrupak profile image
Rupak Dey •

Thank you!
I've added this in the edit.