Category: CSS

  • CSS Animated Button

    <!DOCTYPE html>
    <html>
    <head>
      <style>
    
    .btn {
      padding: 15px 25px;
      background: #2196F3;
      color: white;
      border: none;
      border-radius: 8px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
    }
    .btn::after {
      content: '';
      position: absolute;
      width: 0;
      height: 100%;
      top: 0;
      left: 0;
      background: rgba(255,255,255,0.3);
      transition: width 0.3s;
    }
    .btn:hover::after {
      width: 100%;
    }
    </style> </head> <body> <button class="btn">Hover Me</button> </body> </html>

    Explanation:

    • Button has a shining effect using ::after.
    • Expands across button on hover.
  • CSS Digital Clock

    <!DOCTYPE html>
    <html>
    <head>
      <style>
    
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      background: black;
      color: lime;
      font-size: 50px;
      font-family: monospace;
    }
    .clock {
      border: 3px solid lime;
      padding: 20px;
      border-radius: 10px;
    }
    </style> </head> <body> <div class="clock">12:45</div> </body> </html>

    Explanation:

    • Just UI styling for a digital clock.
    • To make it functional, you’d add JavaScript.
  • CSS Accordion

    <!DOCTYPE html>
    <html>
    <head>
      <style>
    
    .accordion input {
      display: none;
    }
    .accordion label {
      display: block;
      padding: 10px;
      background: #333;
      color: white;
      cursor: pointer;
      margin-top: 5px;
    }
    .accordion div {
      max-height: 0;
      overflow: hidden;
      transition: max-height 0.3s;
      background: #f4f4f4;
      padding: 0 10px;
    }
    .accordion input:checked + label + div {
      max-height: 100px;
      padding: 10px;
    }
    </style> </head> <body> <div class="accordion">
    &lt;input type="checkbox" id="q1"&gt;
    &lt;label for="q1"&gt;What is CSS?&lt;/label&gt;
    &lt;div&gt;CSS stands for Cascading Style Sheets.&lt;/div&gt;
    
    &lt;input type="checkbox" id="q2"&gt;
    &lt;label for="q2"&gt;Why use CSS?&lt;/label&gt;
    &lt;div&gt;It makes websites look beautiful.&lt;/div&gt;
    </div> </body> </html>

    Explanation:

    • Uses hidden checkboxes + CSS :checked.
    • Expands/collapses without JS.
  • CSS Progress Bar

    <!DOCTYPE html>
    <html>
    <head>
      <style>
    
    .progress {
      background: #ddd;
      border-radius: 20px;
      overflow: hidden;
      width: 300px;
      height: 25px;
    }
    .progress-bar {
      width: 70%; /* progress value */
      height: 100%;
      background: linear-gradient(to right, green, lime);
      text-align: center;
      color: white;
      line-height: 25px;
    }
    </style> </head> <body> <div class="progress">
    &lt;div class="progress-bar"&gt;70%&lt;/div&gt;
    </div> </body> </html>

    Explanation:

    • A container with a colored bar inside.
    • Can be styled with gradients.
  • Modal Popup

    <!DOCTYPE html>
    <html>
    <head>
      <style>
    
    body { font-family: Arial; }
    .modal {
      display: none;
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(0,0,0,0.5);
      justify-content: center;
      align-items: center;
    }
    .modal:target {
      display: flex; /* Show when targeted */
    }
    .modal-content {
      background: white;
      padding: 20px;
      border-radius: 10px;
      width: 300px;
    }
    </style> </head> <body> <a href="#myModal">Open Modal</a> <div id="myModal" class="modal">
    &lt;div class="modal-content"&gt;
      &lt;h3&gt;Modal Title&lt;/h3&gt;
      &lt;p&gt;This is a CSS-only modal.&lt;/p&gt;
      &lt;a href="#"&gt;Close&lt;/a&gt;
    &lt;/div&gt;
    </div> </body> </html>

    Explanation:

    • Uses CSS :target selector instead of JS.
    • Clicking link shows the modal.
  • Tooltip on Hover

    <!DOCTYPE html>
    <html>
    <head>
      <style>
    
    .tooltip {
      position: relative;
      display: inline-block;
      cursor: pointer;
    }
    .tooltip .tooltiptext {
      visibility: hidden;
      background: black;
      color: #fff;
      text-align: center;
      padding: 5px;
      border-radius: 5px;
      
      position: absolute;
      bottom: 125%; /* Position above */
      left: 50%;
      transform: translateX(-50%);
      opacity: 0;
      transition: opacity 0.3s;
    }
    .tooltip:hover .tooltiptext {
      visibility: visible;
      opacity: 1;
    }
    </style> </head> <body> <div class="tooltip">
    Hover me
    &lt;span class="tooltiptext"&gt;Tooltip info here&lt;/span&gt;
    </div> </body> </html>

    Explanation:

    • Uses :hover to show hidden text.
    • opacity + transition makes it fade smoothly.
  • Pricing Table

    <!DOCTYPE html>
    <html>
    <head>
      <style>
    
    body {
      display: flex;
      justify-content: center;
      gap: 20px;
      font-family: Arial, sans-serif;
      background: #f9f9f9;
      padding: 40px;
    }
    .plan {
      background: white;
      padding: 20px;
      border-radius: 12px;
      width: 200px;
      text-align: center;
      box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    }
    .plan h3 {
      margin-bottom: 10px;
    }
    .plan p {
      color: gray;
    }
    .plan button {
      margin-top: 15px;
      background: green;
      color: white;
      border: none;
      padding: 10px;
      border-radius: 8px;
      cursor: pointer;
    }
    .plan button:hover {
      background: darkgreen;
    }
    </style> </head> <body> <div class="plan">
    &lt;h3&gt;Basic&lt;/h3&gt;
    &lt;p&gt;$9/month&lt;/p&gt;
    &lt;button&gt;Buy&lt;/button&gt;
    </div> <div class="plan">
    &lt;h3&gt;Pro&lt;/h3&gt;
    &lt;p&gt;$19/month&lt;/p&gt;
    &lt;button&gt;Buy&lt;/button&gt;
    </div> <div class="plan">
    &lt;h3&gt;Premium&lt;/h3&gt;
    &lt;p&gt;$29/month&lt;/p&gt;
    &lt;button&gt;Buy&lt;/button&gt;
    </div> </body> </html>

    Explanation:

    • Cards aligned with flexbox.
    • Each plan is a styled box.
    • hover makes buttons interactive.
  • Login Form

    <!DOCTYPE html>
    <html>
    <head>
      <style>
    
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      background: #f0f0f0;
      font-family: Arial, sans-serif;
    }
    .login-box {
      background: white;
      padding: 30px;
      border-radius: 12px;
      box-shadow: 0 4px 10px rgba(0,0,0,0.2);
      width: 300px;
    }
    .login-box h2 {
      text-align: center;
      margin-bottom: 20px;
    }
    .login-box input {
      width: 100%;
      padding: 10px;
      margin: 8px 0;
      border: 1px solid #ccc;
      border-radius: 8px;
    }
    .login-box button {
      width: 100%;
      padding: 10px;
      background: blue;
      color: white;
      border: none;
      border-radius: 8px;
      cursor: pointer;
    }
    .login-box button:hover {
      background: darkblue;
    }
    </style> </head> <body> <div class="login-box">
    &lt;h2&gt;Login&lt;/h2&gt;
    &lt;input type="text" placeholder="Username"&gt;
    &lt;input type="password" placeholder="Password"&gt;
    &lt;button&gt;Login&lt;/button&gt;
    </div> </body> </html>

    Explanation:

    • box-shadow gives depth.
    • input and button styled for modern UI.
  • Image Gallery with Hover Effect

    <!DOCTYPE html>
    <html>
    <head>
      <style>
    
    .gallery {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 15px;
      padding: 20px;
    }
    .gallery img {
      width: 100%;
      border-radius: 10px;
      transition: transform 0.3s;
    }
    .gallery img:hover {
      transform: scale(1.1);
    }
    </style> </head> <body> <div class="gallery">
    &lt;img src="https://via.placeholder.com/200" alt="1"&gt;
    &lt;img src="https://via.placeholder.com/200" alt="2"&gt;
    &lt;img src="https://via.placeholder.com/200" alt="3"&gt;
    &lt;img src="https://via.placeholder.com/200" alt="4"&gt;
    &lt;img src="https://via.placeholder.com/200" alt="5"&gt;
    &lt;img src="https://via.placeholder.com/200" alt="6"&gt;
    </div> </body> </html>

    Explanation:

    • display: grid creates a gallery.
    • hover + scale gives zoom effect.

  • Animated Loading Spinner

    <!DOCTYPE html>
    <html>
    <head>
      <style>
    
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      background: #f9f9f9;
    }
    .spinner {
      width: 60px;
      height: 60px;
      border: 8px solid #ddd;
      border-top: 8px solid blue;
      border-radius: 50%;
      animation: spin 1s linear infinite;
    }
    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }
    </style> </head> <body> <div class="spinner"></div> </body> </html>

    Explanation:

    • border-top gives a colored arc.
    • @keyframes rotates the circle infinitely.