What is the technique to achieve a seamless blur effect?

Is there a way to create a smooth blur similar to a gradient transitioning from transparent to dark?

.img {
  background: url(https://4kwallpapers.com/images/walls/thumbs_2t/13551.jpg);
  background-size: cover;
  background-position: center;
  width: 500px;
  height: 300px;
  position: relative;
}

.img .shadow {
  content: "";
  height: 150px;
  bottom: 0;
  width: 100%;
  position: absolute;
  pointer-events: none;
  left: 0;
  background: linear-gradient( 360deg, rgb(0 0 0 / 100%) 0%, rgba(255, 255, 255, 0) 100%);
  backdrop-filter: blur(10px);
}
<div class="img">
  <div class="shadow"></div>
</div>

Answer №1

Mixing mask and background

.image {
  background: url(https://4kwallpapers.com/images/walls/thumbs_2t/13551.jpg);
  background-size: cover;
  background-position: center;
  width: 500px;
  height: 300px;
  position: relative;
}

.image:before {
  content: "";
  position: absolute;
  height: 200px;
  inset: auto 0 0;
  pointer-events: none;
  -webkit-mask: linear-gradient(#0000, #000 90%);
  background: linear-gradient(#0000, #0005 70%,#000);
  backdrop-filter: blur(10px);
}
<div class="image">
</div>

Answer №2

To achieve a layered effect, consider stacking multiple elements on top of each other. Start with the tallest and least blurred layer to minimize the visibility of the blur against the original image. Subsequent layers can be progressively shorter and more blurred, creating a cascading blur effect. The layers can then be seamlessly blended together using a mask.

Feel free to customize the parameters based on your preferences:

.img {
  background: url(https://4kwallpapers.com/images/walls/thumbs_2t/13551.jpg);
  background-size: cover;
  background-position: center;
  width: 500px;
  height: 300px;
  position: relative;
}

.img .shadow {
  content: "";
  height: calc(150px * var(--n) / 4);
  bottom: 0;
  width: 100%;
  position: absolute;
  pointer-events: none;
  left: 0;
  background: linear-gradient( 360deg, rgb(0 0 0 / 75%) 0%, rgba(255, 255, 255, 0) 150px);
  -webkit-mask: linear-gradient(0deg, #000, #0000);
  mask: linear-gradient(0deg, #000, #0000);
  backdrop-filter: blur(calc(10px / var(--n)));
}

.shadow:nth-child(1) {
  --n: 4;
}

.shadow:nth-child(2) {
  --n: 3;
}

.shadow:nth-child(3) {
  --n: 2;
}

.shadow:nth-child(4) {
  --n: 1;
}
<div class="img">
  <div class="shadow"></div>
  <div class="shadow"></div>
  <div class="shadow"></div>
  <div class="shadow"></div>
  <div class="shadow"></div>
</div>

Answer №3

To eliminate the blur filter, you can utilize the mask property (in this code snippet, simply hover over the image):

.image {
  width: 800px;
  height: 450px;
  position: absolute;
  background: url(https://example.com/image.jpg);
  background-repeat: no-repeat;
}

.linear-filter-top-to-bottom {
  -webkit-mask: -webkit-linear-gradient(black, transparent 100%, black);
  -webkit-mask: linear-gradient(black, transparent 100%, black);
  -webkit-filter: blur(24px);
  mask: url("#linear-mask");
  filter: url("#filter");
}
.linear-filter-top-to-bottom:hover {
  mask: none;
  filter: none;
  -webkit-mask: none;
  -webkit-filter: none;
}
.filter-border {
  width: 800px;
  height: 450px;
}

.container {
  width: 800px;
  height: 450px;
}
<div class="container">
  <div>
    <img class="image" />
    <img class="linear-filter-top-to-bottom image" />
  </div>
  <svg height="0">
    <defs>
      <mask id="linear-mask">
        <rect class="filter-border" fill="url(#l1)"></rect>
        <linearGradient id="l1" x1="0" y1="0" x2="0" y2="1">
          <stop stop-color="white" offset="0%" />
          <stop stop-color="black" offset="40%" />
          <stop stop-color="white" offset="100%" />
        </linearGradient>
      </mask>
      <filter id="filter">
        <feGaussianBlur in="SourceGraphic" stdDeviation="8" />
      </filter>
    </defs>
  </svg>
</div>

Answer №4

What do you think of this?

I'm not entirely sure if I've grasped your question correctly.

Try hovering over it to see the difference it makes.

.img {
  background: url(https://4kwallpapers.com/images/walls/thumbs_2t/13551.jpg);
  background-size: cover;
  background-position: center;
  width: 500px;
  height: 300px;
  position: relative;
}

.shadow {
  height: 150px;
  bottom: 0;
  width: 100%;
  position: absolute;
  pointer-events: none;
  backdrop-filter: blur(5px);
  -webkit-mask: linear-gradient(transparent, black 80%);
  
  border-right: 1px solid white;
  transition: .5s ease-in-out;
}

.img:hover .shadow {
  width: 0%;
}
<div class="img">
  <div class="shadow"></div>
</div>

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

Running PHP code within an HTML file served by PHP

A unique and innovative approach was taken by incorporating a DIV element in the HTML code, which dynamically populates with content from the main_login.php file. The main_login.php file plays a crucial role in loading the homepage with member-specific con ...

Sending a tailored query string through a form

Currently, when I submit a form, it directs me to the URL www.domain.com/search/?maxprice=10000000. However, I want it to redirect me to a custom URL such as www.domain.com/search/maxprice_10000000/ I came across some JavaScript code that was supposed to ...

Creating a HTML5 canvas animation of an emoticon winking to add a fun touch to your

Currently, I am facing a challenge in animating an emoticon that was initially sketched on canvas. While following a tutorial to implement draw and clear animations using frames, I haven't been able to achieve the desired outcome. With 6 frames of the ...

Select and activate a single input from multiple options in Angular

I have multiple input fields with corresponding buttons that enable the input when clicked. I would like the behavior of the buttons to work in such a way that when one button is clicked, only that specific input field is enabled while the others are disab ...

Mastering the alignment of tab content on Bootstrap 5 to ensure it always displays on the right side

With Bootstrap 5, I've managed to implement tab content that remains visible regardless of the active tab: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="23414c4c5750575142536 ...

"What is the best approach to adjusting the width of one div based on the width of another div using CSS Grid

As a beginner in programming, I'm trying to work with CSS Grid but facing some challenges. My goal is to create a component with two columns: the left column should have a width of minmax(570px, 720px), and the right column should be minmax(380px, 10 ...

What reasons could explain why the more efficient approach of offering an initial portion of data is not faster in practice?

My website contains numerous pages with a plethora of small images that need to be loaded. To enhance user experience, I devised two methods to first display a subset of the content without waiting for the entire page to load. The data is stored in a .json ...

What is the most effective method for customizing non-MUI elements within an MUI framework?

As someone new to React and development in general, I understand that there are various ways to style elements within React itself: importing CSS, using locally scoped CSS modules, implementing CSS-in-JS via libraries like Styled Components or Emotion, ut ...

Is jQuery Mobile Autocomplete's search feature activated after typing 3 letters?

Hello there, I am in the process of creating a website and have implemented an autocomplete field. However, I am facing an issue due to having over 1000 <li> elements within the <ul>, making it slow especially on mobile devices. I would like t ...

Submitting the form with a target of _blank will result in the form being submitted on both a

I am currently working on a form that includes both a "Submit" button and a "Preview" button. While the submit button is functioning correctly, I am experiencing an issue with the Preview button. When clicked, it opens up a new page with the preview as in ...

Having difficulty configuring Compass in WebStorm

Trying to integrate Compass into an existing WebStorm project has been challenging for me as the CSS files are not linking properly. Despite my efforts to modify the relative links, I have not yet managed to resolve the issue. The folders and config.rb we ...

The interaction of a horizontal scroll bar on a CSS Grid layout triggers the appearance of a vertical scroll bar

I am facing a challenge with my HTML layout. In Chrome, when the horizontal scroll bar is visible, a vertical scroll bar also appears. However, in Firefox, everything works fine. This issue seems to be related to the height of the div not auto-scaling prop ...

Display an echo within a DIV

Encountering a frustrating issue and seeking assistance. The problem seems to involve loading a page into a DIV. I've created a form for updating database information in a single file with PHP code, loaded into a DIV. When accessing the page directly ...

Adjusting the text and background hues using JavaScript results in an immediate reversal

Attempting to dynamically change the text color and background color based on user input in the textbox. While it initially works, the color changes only flash for a brief moment before reverting back. <!DOCTYPE html> <html> <head> ...

fancybox thumbs will never function properly

I recently made the switch from using PrettyPhoto to FancyBox for my gallery, which utilizes Isotope for filtering and animations. However, I am encountering an issue where the images appear but the thumbnails are missing. In the developer tools, there is ...

What is the best way to replicate a div's background color using an image within the body element?

I am looking to achieve a layout similar to the one below: https://i.sstatic.net/1cOYw.png The dark grey color represents the sidebar, but I want to use this color as a repeating vertical image in the body element without covering the footer (light gray) ...

Support for Arabic in database, PHP, and JavaScript

After inputting an Arabic comment into a textarea on the site, it displays correctly as "عربي" and is successfully sent to the database. However, upon refreshing the page, the text appears garbled: "عربÙ�". I attempted to directly enter s ...

Adjust Element Width Based on Scroll Position

I'm attempting to achieve a similar effect as seen here: (if it doesn't work in Chrome, try using IE). This is the progress I've made so far: http://jsfiddle.net/yuvalsab/op9sg2L2/ HTML <div class="transition_wrapper"> <div ...

What is the best method for centering text input within an Angular Material toolbar?

Can anyone help me with aligning input elements with buttons on an Angular Material toolbar? Check out the code pen: http://codepen.io/curtwagner1984/pen/amgdXj Here is the HTML code: <md-toolbar class="md-hue-1" layout-align="start center" style="mi ...

Is it feasible to embed an entire linked CSS file within Jade?

I keep getting recommendations from Google's PageSpeed Insights to avoid using links for CSS files and instead include the styles directly under a style tag. I'm wondering if there is a way in Jade to specify a CSS file and have its contents pull ...