Prevent Blurry Image Edges from Becoming Undefined During CSS Transitions with CSS Filter Blur

Keeping the edges of an image crisp and defined during a CSS transition can be challenging when adding negative margin. How can you maintain image clarity while applying or removing a filter blur class?

Tested in:

  • Firefox 37: Functioning perfectly!
  • Chrome 42: Some blurriness observed at the border between the image and parent element
  • IE9: Not working as expected

Experience the example yourself: Codepen

HTML:

<link href='http://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Hind' rel='stylesheet' type='text/css'>
<div class="container">
  <img class="blur" src="http://budgetstockphoto.com/bamers/stock_photo_spectrum.jpg"/>
</div>
<div class="col">
<h2 class="montserrat">Hover Over Image</h2>
<hr>
  <p class="hind">Preventing an image from having undefined blurry edges can be achieved by adding negative margin, but during a CSS transition this fails. As shown on-hover, the image edges become blurred. How can we ensure image definition during a CSS transition with filter blur?<br><br>Try hovering over the image!</p>
</div>

CSS:

html,body{
  margin:0;
  text-align:center;
  background:#F8F8F8;
  height:100%;
}

h2{
  margin:1em 0;
  padding:0;
  line-height:1;
  color:#111;
}
p{
  margin:1em 0;
  padding:0;
  line-height:1;
  text-align:justify;
  color:#999;
}

.montserrat{
    font-family: 'Montserrat', sans-serif;
}
.hind{
    font-family: 'Hind', sans-serif;
}
hr { 
  width:100%;
  display: block; 
  height: 1px;
  border: 0; 
  border-top: 1px solid #222;
  margin: 1em 0; 
  padding: 0; 
  line-height:0;
}

.col{
  max-width:400px;
  display:inline-block;
  height:100%;
  float:left;
  background:#333;
  padding-left:20px;
  padding-right:20px;
}

.container{
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  width:10%;
  display:inline-block;
  padding-top:10%;
  position:absolute;
  overflow:hidden !important;
  border-radius:50%;
  -webkit-filter: blur(0px); -moz-filter: blur(0px); -o-filter: blur(0px); -ms-filter: blur(0px); filter: blur(0px);/*prevents image from overflowing*/
}

.container img{
  position:absolute;
  min-width:calc(100% + 30px);
  height:calc(100% + 30px);
  left:-15px;
  right:-15px;
  top:-15px;
  bottom:-15px;
  -webkit-transition: .5s ease-in-out;
}

.blur{
        -webkit-filter: blur(5px); -moz-filter: blur(5px); -o-filter: blur(5px); -ms-filter: blur(5px); filter: blur(5px);
}

A touch of jQuery:

$(document).ready(function(){
    $('img').hover(function(){
        $(this).toggleClass('blur');
    }); 
});

Answer №1

For Chrome users, a simple solution is to implement:

  backface-visibility: hidden;

When applied to images, this can help resolve blurring issues.

Answer №2

Enhance the effects of filters on images, animations, and transitions by applying them to content in HW-accelerated mode. You can easily force the browser to use this mode by adding a simple 3D transform:

.container img{
    transform: translateZ(0.1px)
}

Check out this example: http://codepen.io/ondrakoupil/pen/GJpaJo The results are much smoother now (tested on Chrome 39 on OS X)

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

Utilizing TemplateFields in GridView for Enhancing jQuery Datatables

I am currently utilizing a GridView in ASP.NET (webforms) to showcase a download link LinkButton inside of a TemplateField. However, I'm facing an issue where the header of the first column is appearing in the body of all rows in the second column, le ...

Challenges encountered with progress bars

Currently, I am working on an Angular app and implementing a progress bar using Angular. However, I have encountered two issues with my progress bar that need to be addressed. The fourth section of web development is titled "from end," and I would like ...

What is the best way to obtain the value of the chosen option from a dropdown menu

I have a dropdown menu in my View that displays different levels of courses: @Html.DropDownListFor(model => model.hobbyhome.HobbyDetailList.First().course, HobbyHomesWebApp.Utility.EnumList.ToSelectList(HobbyHomes.Model.Course.Advance, "Selec ...

What is the best way to align items in the Bootstrap navbar?

I attempted to center elements within a Bootstrap 5 navbar using a Vue template, but neither display flex with justify content: center nor text-center worked for me. I also tried applying align-items to the elements without success. My goal is to have th ...

What are some effective ways to implement a real-time tracking system for shipments using Angular JS?

https://i.sstatic.net/Bg0Gy.png I am currently working on developing a shipment tracker using Angular, HTML5, and CSS3. Does anyone have any suggestions on how to dynamically create the shipment tracker using AngularJS? My initial plan is to incorporate ...

How can I connect an IDE to my Rails project for better development?

I am interested in incorporating an online terminal or IDE into my Rails application. Is there a method to seamlessly integrate existing IDEs with Rails, or develop a new one specifically for this purpose? I have scoured Google but could not find any rele ...

Tips for displaying a notification after a successful form submission using jQuery and AJAX

While attempting to submit a PHP form using jquery $.ajax();, I have encountered a peculiar issue. The form is successfully submitted, however, when I try to display an alert message - alert(SUCCESS); on success, it does not work as expected. Any ideas on ...

Unable to retrieve the data through ajax GET due to a URL error

While attempting to pass an ID to the Quizz page and use AJAX to retrieve data when the page loads, I encountered an error message. HTTP404: NOT FOUND - The server did not find anything that matches the requested URI (Uniform Resource Identifier). (XHR)G ...

Is there a way to stop a music track from playing?

function playMusic(){ var music = new Audio('musicfile.mp3'); if (music.paused) { music.play(); } else { music.pause(); } } <input type="button" value="sound" onclick="playMusic()" ...

Using jQuery to assign a value within a c:foreach loop

I am currently working on a project that requires fetching values via an ajax request using a specific id. Subsequently, I need to retrieve the JSON List returned and inject it into a jstl foreach loop. Here is the snippet of code for the ajax GET request: ...

How can I incorporate classes from multiple CSS files into my WordPress theme?

Currently, I am utilizing wp_enqueue_style to incorporate two CSS files within a single function. However, the issue that arises is when I try to apply a class, it seems that only classes from one of the files can be utilized and it ends up overriding anot ...

Add a border around the div that runs into the header

I am looking to create a border and header similar to this example: [![][1]][1] Is there a CSS solution for achieving this design? One method I have tried that seems to work is: .header{ margin-top:-10px; background:#fff; } Are there any alternate opti ...

Attention: The PageContainer component requires React component classes to extend React.Component

I recently started using react-page-transitions in my project and encountered the following warning message: "PageContainer(...): React component classes must extend React.Component." Here is a snippet of my code: import React from 'react'; ...

Upload files using jQuery along with additional data included

Utilizing jQuery for AJAX uploading with additional data. I am referencing the Stackoverflow code found here How can I upload files asynchronously? and implemented the following code: var formData = new FormData($('form')[0]); $. ...

Uploading information from a confirmation page to the controller

Within this cshtml file, I have included a model. This specific page serves as a confirmation page where the user is able to review and verify that all entered information is correct before proceeding. There is a link button (not part of the displayed cod ...

Is it possible to access the preceding/succeeding values of a jQuery object by simply using a key?

I'm facing a bit of difficulty with this task. All I have is a grade number ranging from -1 to 5, which is used as the key, and from that, I need to create 1 previous and 1 next link. Here's what I've managed to come up with: var grUrl = { ...

Open a new window, but the 'To' field address is set to mailto:[email protected]

In my JavaScript code, I have a functionality to open a mail client in a new window for sending an email: <a onClick="javascript:window.open('mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1d4d2c4d3e1d5c4d2d58f ...

Transformed 700 audio players compartmentalized within a nested tab interface. Optimal tab coding techniques include jquery, ajax

We are currently working on developing a nested tab interface that will include 700 audio players for MP3 files all on the same page within various tabs. However, only one audio player will be visible at a time and will only appear when the tab is clicked. ...

Aligning font awesome icons vertically to the bottom position

It seems like there might be a simple solution that I'm overlooking. Is it feasible to align the glyph content or glyph itself at the bottom of a parent element? In this demonstration, how can I ensure all the icons are positioned at the bottom, rega ...

Could you please guide me on resolving the Blazor/Bootstrap 5 CSS problem related to styling "striped" tables?

Looking for a solution to fix a CSS issue involving Bootstrap 5 "table-striped" and displaying Blazor Razor components. In my Blazor/Bootstrap 5 page, I have a table displaying content fetched from a service at runtime. Initially, the Bootstrap CSS is vis ...