Numerous filter passages

How can I make an image white on hover using CSS filters and transitions?

.uni-im img {
    filter: brightness(0) invert(1);
}

I have added a transition property for a smooth effect:

.uni-im img {
    filter: brightness(0) invert(1);
    transition: filter .15s linear;
}

However, the transition affects both the brightness and invert properties simultaneously. Is there a way to make it turn white directly without passing through black?
Is this achievable with pure CSS?

Here's an example of what I'm trying to achieve:

div {
  background: white;
  border: 1px solid #ccc;
  padding: 20px;
  display: inline-block;
  transition: background 2s linear;
}
img {
  width: 30px;
  height: 30px;
  transition: filter 2s linear;
}

div:hover {
  background: #3F85CE;
}
div:hover img {
  filter: brightness(0) invert(1);
}
<div>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA3WAAAN1gGQb3mcAAAAB3RJTUUH4gsGEwwX9OWpBgAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTFH80I3AAAC00lEQVR4Xu2Z3UrEMBCFqyirq/iHLKggeCe6CuKFPzeuLIpXXqh4Iejb+Hq+ks7USZ3NJmltNqWrpxDczaYz53ydpGnNMhwgAAIgAAIgAAIgAAIgAAIgAAIgAAIgAAKlBJau3j8+29hI+VKp+pgBbTTt0hTjMXiuSZYsQWT...

Answer №1

To enhance the visibility of the effect, I've devised a new code snippet where the image's color is utilized as a background.

Rest assured, this method will yield similar results for your specific scenario.

All you need to do is modify the filters that you are currently implementing.

.test {
  width: 200px;
  height: 150px;
  background: cyan;
  margin: 20px;
  transition: filter 4s;
}

.test:hover {
  filter:  grayscale(1) brightness(1.5);
}
<div class="test"></div>

Answer №2

The code snippet you shared specifies a 2 second transition duration. If the transition time is reduced, the black color will not be visible.

For example:

div {
  background: white;
  border: 1px solid #ccc;
  padding: 20px;
  display: inline-block;
  transition: background 100ms linear;
}
img {
  width: 30px;
  height: 30px;
  transition: filter 100ms linear;
}

You can also eliminate the transition effect on the image element. This way, the background will transition from white to blue over .15 seconds, while the image will instantly change from blue to white without going through the black color in between.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtaining a fingerprint image from a scanner and incorporating it into a user registration form

I am currently developing a project using PHP. I am interested in integrating a fingerprint scanner to capture images for user registration forms and then saving them to a database. Is this feasible? If so, I would appreciate any guidance on how to imple ...

Prevent certain parts of an element from displaying using CSS

By utilizing the CSS3 property clip-path, I am able to easily clip elements so that only a specified area remains visible. While this feature is useful, I'm wondering if there is a method to exclude an area so that everything except the specified path ...

Bug with Image Scaling on iPhone 6+ in Unsemantic Grid

Check out this website: I need help fixing the responsive images on iPhone6. Which CSS code is missing? Is this a specific grid bug affecting iPhone 6+ only? When testing the website on different viewports, everything appears fine. However, when my broth ...

Dreamweaver and jQuery collaboration for displaying PDFs in a container

I am currently utilizing the jQuery accordion functionality within the latest version of Dreamweaver. My goal is to link a specific PDF with each account so that when an account is selected, the corresponding PDF will open in the designated "content goes h ...

There appears to be a malfunction with WebRupee

I have incorporated the new rupee sign into my website to represent Indian currency. Below is the code snippet I used: For the script, I included " and also added the following: <span class="WebRupee">Rs.</span> 116,754.00 To style it using ...

Generate a vertical line that spans the entire length of the webpage in a vertical direction

Looking for a way to add vertical borders that span the entire webpage to some text? Check out this HTML snippet: <div id="vLine"> <h1>text</h1> </div> Here's the accompanying CSS: #vLine { height: 100%; width: 5 ...

Prevent the text within the textarea from wrapping onto the next line

My challenge involves a textarea where text overflows onto the next line when it exceeds the maximum characters. However, I want the text to continue on the same line with a scroll bar for better visibility. Here's an illustration: text here flows on ...

The fonts appear differently when working on a Mac but show up as Times New Roman when displayed on Windows in development

Currently, I am utilizing react combined with nextjs for server-side rendering and bootstrap. Within my component, I have integrated bootstrap via a CDN: <Head> <title>{title}</title> <meta charSet="utf-8" /> < ...

Crafting a Presentation of Inspirational Words

I'm currently in the process of creating a photo album using AngularJS and CSS, but I'm facing an issue with the pictures showing up too large. Despite my efforts to resize them, they still appear oversized. I've even tried resizing them in ...

Issues concerning margins and scroll bars

As a C++ programmer diving into the world of HTML5 and Javascript, I find myself struggling with layouts and seeking advice and constructive criticism. One issue that keeps popping up is the appearance of unwanted scroll bars when I add margin or padding t ...

Expanding and collapsing a div using jQuery when an image is clicked

I have a query that spans across two areas - CSS styling and JQuery functionality. The primary concern I have is related to my code snippet below. When the user clicks on the circular profile image, ideally, the "profiledrop" div should become visible. ...

Alter the text color once the halfway point is reached at an angle of 175 degrees

I want the text color to turn white when the background color changes to blue after reaching 50% height with a 175 degree angle. Check out this Fiddle .bg { background: linear-gradient(175deg, #e2e2e2 50%, #435289 50%); color:#000; } <div ...

Space within a receptacle

As a newcomer to bootstrap5, I am encountering whitespace issues on the left side of my screen. While everything looks fine in full-screen mode, the whitespace around the image persists when I test responsiveness. https://i.sstatic.net/gZTq5.jpg Despite t ...

The website is missing a scrollbar

I am having trouble getting the scroll bar to show up on my website, even after adding the following CSS: { overflow-y:scroll; } I have tried putting it in both the body and HTML sections of the CSS. If you'd like to take a look at the website, her ...

Centralize and confine the menu division

I have been working on creating a hover menu using CSS and Bootstrap, specifically for flex grid layouts. However, I have run into an issue where my menu is only as wide as its parent div. Furthermore, I am struggling to center the hover menu relative to ...

Tips for preventing line breaks in CSS while adjusting zoom levels on a webpage

While adjusting the zoom level on the page, I noticed that the text breaks and separates onto another line. The first quick link appears fine, however there seems to be an issue with the second and third quick links as well as the lorem text. Apologies f ...

Displaying Image from Jquery Ajax Response

I have a PHP script that can resize images with specified dimensions by passing the width and height as variables like so: resize.php?width=100&height=200. The content-type of this PHP script is set to image/jpg. Additionally, I have an HTML page wher ...

Click on the shadowed div element to interact: inset

Is there a way to make elements clickable/focusable within a div that has an inset shadow, like the .calendar in this example? Check out this code snippet: https://jsfiddle.net/axel50397/846ostv5/9/ <div class="calendar"> <div class="card-dec ...

The first div should be hidden when the toggle is activated

I am currently working on a CRUD project and incorporating some Javascript/JQuery into it. I have a button labeled "Add", which, when clicked, displays a specific div element. However, I'm facing an issue where the div is already visible before the us ...

Color of Bootstrap tooltip arrow outline and fill

How can I customize the background color and border color of the tooltip arrow in Bootstrap 4? $(function() { $('[data-toggle="tooltip"]').tooltip() }) .tooltip-main { width: 15px; height: 15px; border-radius: 50%; font-weig ...