DEV Community

Cover image for 🔥 Top 10 Mind-Blowing Front-End Tricks! 🔥
WEBDEVTALES
WEBDEVTALES

Posted on • Originally published at webdevtales.com

🔥 Top 10 Mind-Blowing Front-End Tricks! 🔥

1. CSS Variables Magic 🎨

💡 Tip: Define reusable values with --custom-properties, then use them throughout your CSS!

:root {
  --main-color: #ff6347;
}
body {
  background-color: var(--main-color);
}
Enter fullscreen mode Exit fullscreen mode

Let me explain using Proper Code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>CSS Variables Magic 🎨</title>
  <style>
    :root {
      --main-color: #ff6347;
      --accent-color: #00bfff;
      --text-color: #ffffff;
    }
    body {
      background-color: var(--main-color);
      color: var(--text-color);
      font-family: Arial, sans-serif;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
    }
    .box {
      background-color: var(--accent-color);
      padding: 50px;
      border-radius: 10px;
      text-align: center;
      font-size: 1.5em;
    }
  </style>
</head>
<body>
  <div class="box">
    This box uses CSS Variables! 🎨
  </div>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode

Output:

CSS Tricks

2. The Hidden Hover Effect 🕵️‍♀️

🎉 Hover effects without adding hover in CSS? Try :not() with child selectors for stealthy hover interactions!

button:not(:hover) {
  background-color: #ddd;
}
Enter fullscreen mode Exit fullscreen mode

Let me explain using Proper Code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Hidden Hover Effect with :not()</title>
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      background-color: #f5f5f5;
    }

    .container {
      display: flex;
      gap: 10px;
    }

    .box {
      width: 100px;
      height: 100px;
      background-color: #3498db;
      transition: background-color 0.3s ease, transform 0.3s ease;
    }

    /* The hidden hover effect */
    .box:hover {
      transform: scale(1.1);
    }

    .box:not(:hover) {
      background-color: #e74c3c; /* Changes all other boxes except the hovered one */
    }
  </style>
</head>
<body>

  <div class="container">
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
  </div>

</body>
</html>


Enter fullscreen mode Exit fullscreen mode

Output:

CSS Tricks

After hovering:

CSS Tricks

3. Border-Radius Hacks 🎯

🔥 Want perfect circles or pill-shaped buttons? Play with percentages in border-radius to create ultra-smooth shapes!

.circle {
  border-radius: 50%;
}
.pill {
  border-radius: 50% / 25%;
}
Enter fullscreen mode Exit fullscreen mode

Let me explain using Proper Code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Border-Radius Hacks 🎯</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 100vh;
      margin: 0;
      gap: 20px;
    }
    .circle {
      width: 100px;
      height: 100px;
      background-color: #ff6347;
      border-radius: 50%;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #fff;
      font-weight: bold;
    }
    .pill {
      width: 200px;
      height: 50px;
      background-color: #00bfff;
      border-radius: 50% / 25%;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #fff;
      font-weight: bold;
    }
  </style>
</head>
<body>
  <div class="circle">●</div>
  <div class="pill">Pill Shape 🎯</div>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode

Output:
Border Radius

4. SVGs as Backgrounds 📐

🚀 Ditch static images! Use inline SVGs to create scalable, sharp backgrounds without slowing your site down!

background: url('data:image/svg+xml,...');
Enter fullscreen mode Exit fullscreen mode

Let me explain using Proper Code:

Continue Reading "🔥 CSS Tricks: Top 10 Mind-Blowing Front-End Hacks That will Blow Your Mind! 🔥"

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay