Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • jQuery
  • AngularJS
  • ReactJS
  • Next.js
  • React Native
  • NodeJS
  • Express.js
  • MongoDB
  • MERN Stack
  • PHP
  • WordPress
  • Bootstrap
  • Tailwind
  • CSS Frameworks
  • JS Frameworks
  • Web Development
Open In App
Next Article:
How to change the color of an image to black and white using CSS ?
Next article icon

How to Drop fill color to change the image color using HTML and CSS ?

Last Updated : 07 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we are going to create a Drop-fill color effect using HTML & CSS in which the image gets colored when we hover over it. It appears when you hover over the image a drop of color falls over the image which changes the color of the image from gray to colored.

Approach: The following approach will be implemented to Drop fill color to change the image color:

  1. Create an HTML file in which we add the text and a div for the image.
  2. Then we have to use the hover property to make our image colored.
  3. We also use pseudo-classes like ::before and ::after in our project.
  4. Use of @keyframes for movement of our drop.

HTML Code:

  • First, create an HTML file (index.html).
  • Then link the CSS file that provides all the animation’s effects to our HTML. It is also placed in inside the <head> section.
  • Coming to the body section of our HTML code:
    • First, we have to create a main div.
    • Then, we give the main div a class and create another div inside the present div to put an image into it.
HTML
<!DOCTYPE html> <html lang="en">  <head>      <link rel="stylesheet" href="style.css"> </head>  <body>     <h1>         hover over the icon to          get the icon colored     </h1>          <div class="main_box">         <div class="img"></div>     </div> </body>  </html> 

CSS Code: CSS is used to give different types of animations and effect to our HTML page so that it looks interactive to all users.

In CSS we have to remind the following points –

  1. Restore all the browser effects.
  2. Use classes and ids to give effects to HTML elements.
  3. Use of :hover to use hover effects.
  4. Use of @keyframes for movement of our drop.
  5. Use of pseudo-classes.
CSS
/* Restoring the browser effects */ *{     margin: 0;     padding: 0;     box-sizing: border-box; }  /* Applying all of the same  functionalities to the body */ body{     display: flex;     justify-content: center;     align-items: center;     background-color: #000;     height: 100vh; }  h1{     color: rgb(0, 255, 115);     margin-right: 2em; }  .main_box{     width: 15em;     height: 15em;     position: relative;     cursor: pointer; }  .img,.main_box::before{     width: 100%;     height: 100%;     background-image: url(gfg.jpg);     background-size: cover;     background-position: center;     background-repeat: no-repeat; }  /* Changing the image to gray color */ .img{     filter: grayscale(100%); }   /* Code for drop of color */ .main_box::before{     content: '';     position: absolute;     top: 0;     left: 0;     clip-path: circle(0 at 50% 0);     transition: all .3s;     z-index: 1; }  .main_box::after{     content: '';     position: absolute;     top: -6em;     left: 50%;     transform: translateX(-50%);     width: 1.25em;     height: 1.25em;     background-image: linear-gradient(#006800 , #014716);     border-radius: 0 10em 10em 10em;     opacity: 0;     transform: rotate(45deg); }  .main_box:hover::after{     animation: neeche 0.5s cubic-bezier(1,0,1,.81); }  .main_box:hover::before{     clip-path: circle(31em at 50% 0);     transition-delay: .5s; }  @keyframes neeche{     from{         opacity: 1;     }     to{         opacity: 0;         top: 6em;     } } 

Complete Code: This is the complete code that describes the Drop fill color to change the image color using HTML and CSS.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <style>          /* Restoring the browser effects */                  * {             margin: 0;             padding: 0;             box-sizing: border-box;         }          /* Applying all of the same          functionalities to the body */         body {             display: flex;             justify-content: center;             align-items: center;             background-color: #000;             height: 100vh;         }                  h1 {             color: rgb(0, 255, 115);             margin-right: 2em;         }                  .main_box {             width: 15em;             height: 15em;             position: relative;             cursor: pointer;         }                  .img,         .main_box::before {             width: 100%;             height: 100%;             background-image: url( https://media.geeksforgeeks.org/wp-content/uploads/20210215161411/geeksforgeeksremovebgpreview.jpg);             background-size: cover;             background-position: center;             background-repeat: no-repeat;         }          /* Changing the image to gray color */         .img {             filter: grayscale(100%);         }          /* Code for drop of color */         .main_box::before {             content: '';             position: absolute;             top: 0;             left: 0;             clip-path: circle(0 at 50% 0);             transition: all .3s;             z-index: 1;         }                  .main_box::after {             content: '';             position: absolute;             top: -6em;             left: 50%;             transform: translateX(-50%);             width: 1.25em;             height: 1.25em;             background-image: linear-gradient(                         #006800, #014716);              border-radius: 0 10em 10em 10em;             opacity: 0;             transform: rotate(45deg);         }                  .main_box:hover::after {             animation: neeche 0.5s                  cubic-bezier(1, 0, 1, .81);         }                  .main_box:hover::before {             clip-path: circle(31em at 50% 0);             transition-delay: .5s;         }                  @keyframes neeche {             from {                 opacity: 1;             }             to {                 opacity: 0;                 top: 6em;             }         }     </style> </head>  <body>     <h1>         hover over the icon to          get the icon colored     </h1>          <div class="main_box">         <div class="img"></div>     </div> </body>  </html> 

Output:

Hovering over the icon changes the colored of GFG logo:

img


Next Article
How to change the color of an image to black and white using CSS ?

R

rahulmahajann
Improve
Article Tags :
  • Technical Scripter
  • Web Technologies
  • Web Templates
  • Technical Scripter 2020

Similar Reads

  • How to randomly change image color using HTML CSS and JavaScript ?
    In this article, we will create a webpage where we can change image color randomly by clicking on the image using HTML, CSS, and JavaScript. The image color will change randomly using the JavaScript Math random() function. Approach: First of all select your image using HTML <img> tag.In JavaSc
    2 min read
  • How to change the color of an image to black and white using CSS ?
    To change an image's color to black and white using CSS. This can be achieved by applying the filter property, which allows you to manipulate the visual effects of an image. We'll explore two different methods for converting an image to grayscale (black and white). Methods to Convert an Image to Bla
    2 min read
  • How to Add Border to an Image Using HTML and CSS?
    Adding a border to an image means putting a line around the image to make it look better and more noticeable. To add a border to an image using HTML and CSS, we can use the <img> tag and apply CSS styles like border, border-width, and border color to customize the border's appearance. Syntax .
    1 min read
  • How to Create an Effect to Change Button Color using HTML and CSS ?
    The color-changing effect of a button is very common but what we are going to do a slightly advanced version of this effect. The background will change like a clip effect rotating at some particular angle. Approach: The approach is to provide two or three background and then rotating them on differe
    3 min read
  • How to Add filter to the background image using CSS?
    Adding filters to background images using CSS allows you to apply visual effects like blur, grayscale, brightness adjustment, and more without modifying the actual image file. CSS provides a set of filter functions that can be applied to elements with background images. This approach enhances design
    3 min read
  • How to change color of PNG image using CSS?
    Given an image and the task is to change the image color using CSS. Use filter function to change the png image color. Filter property is mainly used to set the visual effect to the image. There are many property value exist to the filter function. filter: none|blur()|brightness()|contrast()|drop-sh
    1 min read
  • How to Add Image in Text Background using HTML and CSS ?
    In this article, we will use HTML and CSS to set the image in the text background. To set the image in the text background, some CSS property is used. To add an image in the text background using HTML and CSS, create a container element (e.g., a `<div>`), set its background to the desired imag
    2 min read
  • How to Change the Background Color of Table using CSS?
    Changing the background color of a table using CSS can help improve the visual appearance of a website or web application. we will learn how to change the background color of the table using CSS with different approaches. These are the following approaches: Table of Content Using Inline CSSUsing Int
    2 min read
  • How to change text color depending on background color using JavaScript?
    The task is to set the foreground color based on the background color so that it will become visible. Here few of the important techniques are discussed. We are going to use JavaScript. Approach: First, select the random Background color(by selecting random RGB values) or a specific one.Use the YIQ
    3 min read
  • How to Change Background Color with Color Range Slider in HTML?
    To Change the Background Color using an HTML rounded slider that dynamically changes the webpage's background as the slider thumb is moved along its track, giving a visual indication of the selected color. The approach provides a convenient method for customizing the visual appearance of the webpage
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences