20 CSS Tricks You Never Knew You Needed

Victoria Wimer
2 min readOct 3, 2024

--

Here are 20 CSS tricks you might not know you needed:

Trick 1: Using :not() to Select Elements Use the :not() pseudo-class to select elements that do not match a certain selector. For example, :not(.header) selects all elements that do not have the class header.

Trick 2: Creating a Triangle with CSS Use CSS borders to create a triangle. For example, .triangle { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 100px solid #ccc; }

Trick 3: Using calc() for Dynamic Measurements Use the calc() function to perform calculations on CSS measurements. For example, width: calc(100% - 20px); sets the width to 100% minus 20 pixels.

Trick 4: Creating a Responsive Image Use the object-fit property to create a responsive image that scales to fit its container. For example, img { object-fit: cover; width: 100%; height: 300px; }

Trick 5: Using :nth-child() to Style Elements Use the :nth-child() pseudo-class to style elements based on their position in a list. For example, li:nth-child(2n+1) { background-color: #ccc; } styles every other list item.

…and 15 more tricks!

Would you like me to elaborate on any of these tricks or provide the remaining 15?

Check out more details on BLACKBOX.AI 👇https://www.blackbox.ai/share/f99a320f-71e7-41ae-bc76-0489eac880a3

Like, Comment and Follow me for more daily tips.

--

--

Victoria Wimer
Victoria Wimer

Written by Victoria Wimer

0 Followers

Daily coding tips Follow me to learn programming https://www.blackbox.ai/

No responses yet