Div vanishes once SVG Gaussian blur is applied

I'm attempting to add a Gaussian blur effect to an element that contains some child nodes with content.

In Chrome, I successfully applied the blur using the following style:

    -webkit-filter: blur(2px);

Unfortunately, Firefox does not support this method. However, Firefox does allow for applying SVG effects to HTML content. In my search for a solution, I came across an example on how to achieve a Gaussian blur effect using SVG in Firefox. You can check out this post and demo.

Here is the CSS code I created:

    #div-with-content{
        -webkit-filter: blur(2px);
        filter: url('#blur');
    }

I then added the following code to the corresponding HTML file:

    <svg:svg>
        <svg:filter id="blur">
            <svg:feGaussianBlur stdDeviation="2"/>
        </svg:filter>
    </svg:svg>

However, when I tested the page, the div-with-content element vanished once the blur was applied. It reappeared when I removed the blur style. I have exhausted all my knowledge trying to troubleshoot this issue. Any assistance would be greatly appreciated.

Answer №1

Maybe it's the way your apostrophes are placed or the use of svg that is causing the issue, but this particular version seems to function flawlessly on Firefox:

CSS:
#div-with-content{
        filter: url("#blur");
    }


HTML:
<svg>
   <filter id="blur">
       <feGaussianBlur stdDeviation="2"/>
   </filter>
</svg>

<div id="div-with-content"> WOohooo</div>

Answer №2

For those looking to blur text specifically, a simple trick can be employed.

p{
   color: transparent;
   text-shadow: 0 0 4px #222;
}

To witness the effect in action, check out this demonstration on jsFiddle

Answer №3

revision

It is possible to load content from an external document, but it must be from the same origin as the HTML document where it is applied.

Remember to include the html page with the SVG effect in the URL along with the ID of the effect (for example,

Instead of using

url('#filter-effect')

you should use

filter: url('index.html#filter-effect')

I didn't fully understand this concept until I came across @RobertLongon's explanation, but now it makes perfect sense. You can consolidate all your SVGs in one document and reference them from other HTML files.

-

New perspective:

The Mozilla Developer Network states:

You have the option to specify SVG styles within the same document or in an external style sheet.

...but there seems to be some discrepancies. Should we file a bug report?

Opt for <style> over <link>

For reasons unknown to me, if you define the .blur class outside the HTML document via <link>, your element may disappear while still taking up space. This might explain why some fiddles work in other responses but fail during implementation. In JSFiddle, styles are added within the document using <style>. To prevent this issue, ensure that you define the .blur class WITHIN the document using <style>...</style>

Another important note:

NOTE: Namespace declarations are not supported in HTML5, so omit the "svg:" in tags for HTML format documents.

Once again, stick to using <style> rather than <link>.

References:
trial and error
mdn: Applying SVG effects to HTML content

Answer №4

While experimenting with a filter in my project, I encountered a similar issue. After some investigation, I realized that the problem was caused by setting the SVG containing the filter to display: none;. Once I removed this styling, the filters became operational and the HTML elements they were affecting appeared correctly on the page.

Answer №5

While it may be a bit delayed, I found that naming the document didn't quite achieve the desired effect for me. However, when I applied the style directly to the element as shown below, everything worked flawlessly:

<div class="imageblur" style="filter:url(#blur) ">

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

Unable to set the width for a div element within the bootstrap grid layout

When trying to set the width of a div tag to 100% within a bootstrap grid system (col-lg-3), I noticed that the div ends up taking the full width of the browser instead of just 100% of its parent(col-lg-3). .sidebar { color: #fff; f ...

Selecting a webpage from a dropdown list to display its specific content within an iframe

I have a dropdown menu similar to this: <form name="change"> <SELECT NAME="options" ONCHANGE="document.getElementById('frame1').src = this.options[this.selectedIndex].value"> <option value="">Choose</option> <opti ...

Apply CodeMirror theme and plugins using an HTML attribute

On my website, I have implemented a CodeMirror text area from . <form><textarea id="code" name="code" codemirror-type='lineNumbers: false, styleActiveLine: true, matchBrackets: true;'>CODE HERE</textarea></form> I added ...

Updating the div#content dynamically with Jquery without the need to refresh the page

After spending countless hours on this forum, I have yet to find a solution that perfectly fits my needs, so I will pose my question. Here is the gist of what I am attempting to accomplish: When the page loads, the default page fades in and displays. Wh ...

Easily validate your email with this straightforward form. Completely puzzled

Today's challenge is tackling the email validation form issue. While searching for a solution, I stumbled upon an interesting code snippet: http://jsfiddle.net/jquery4u/5rPmV/ dyingOverHere(); The code seems to work flawlessly in the demo provided. ...

The masonry reorganization is behaving strangely

I've recently started using masonry for the first time and you can check it out here: Although I have managed to set it up, I am facing some issues with its positioning of boxes when dragging items in. For example, instead of placing a medium-sized ...

How can you utilize jQuery to export multiple-page HTML content into a PDF document?

I'm having trouble exporting HTML to PDF using jQuery, especially when the HTML content spans multiple pages in the PDF file. Below is my current code snippet: $("body").on("click", "#downloadPDF", function () { html2canvas($('#dow ...

Complete a form when a link or button on the webpage is clicked

I have a variety of links and buttons on my webpage, and they are generated dynamically. I am unable to assign an onclick event to each one individually. My goal is to submit form data to the next page whenever any link or button on the page is clicked. ...

Add drop caps to every individual word within a hyperlink

Is there a way to recreate the menu effect similar to using CSS fonts and drop caps for each word? I'm aware of the CSS code: p.introduction:first-letter { font-size : 300%; } that enlarges the first character of the first word, but I want this ef ...

Adjust the height and width dynamically in CSS/HTML based on various screen dimensions

There are 2 major concerns I have regarding this layout : .feature_content (with a grey background) does not adjust its height and width to different screen sizes. Currently, on large screens, .feature_content is positioned far from the footer. There is ...

Ways to align grid components at the center in MUI frameworks?

I am brand new to using MUI and currently experimenting with the grid functionality. <Grid className={classes.grid} container spacing={{ xs: 2, md: 3 }} columns={{ xs: 4, sm: 8, md: 12 }}> {data.data.map((item, index) => { ...

What is the method for obtaining a unique id that changes dynamically?

Having trouble accessing the dynamically generated ID in jQuery? It seems to work fine in JavaScript but not in jQuery. Here's an example of the issue: My jQuery code: var img = $("#MAP"+current_img_height); $("#map").css({'height': img.h ...

Unable to place an absolutely positioned Div within relative parent containers

After applying the id "enterGame" with position: absolute, I noticed that the div disappears. Even when I tried adding position: relative to the body or html tag, the div remained invisible. The relevant code snippet is as follows: html { height: 10 ...

Is it possible to create vertical-floating elements using CSS?

Can anyone help with a solution to my problem illustrated in the image? I am dealing with a DIV element of fixed height that contains a List. I need this List to display as columns, each list item having a fixed width. If there are too many elements in th ...

Error: The value property is undefined and cannot be read at the HTMLButtonElement

I'm currently working on a project where I need to display a dropdown menu of buttons using Pug in order to render an HTML page. To achieve this, I am using the getElementsByClassName('dropdown-item') method to retrieve all the buttons in an ...

Scraping HTML data without <div> tags with Scrapy - how to do it?

After spending hours attempting to extract a specific data set for use with Scrapy in a web scraping project, here is the current python code: bedrooms_info = house_listing.css( '.search-results-listings-list__item-description__charact ...

Integrating external JavaScript widgets into the web application in real-time

I am currently engaged in a React js project that involves the dynamic addition of third party scripts (widgets) to the web app. These widgets encompass various third party platforms such as Twitter, Instagram, Youplay, Youtube, and more. The existing co ...

What is the most effective approach to seamlessly conceal and reveal a button with the assistance

I have two buttons, one for play and one for pause. <td> <?php if($service['ue_status'] == "RUNNING"){ $hideMe = 'd-none'; } ?> <a href="#" class="btn btn-warning ...

Transform the look of an inactive hyperlink

Can the visual style of an HTML link be modified when it is disabled? For instance, by implementing something like this: a.disabled { color:#050; } <a class="disabled" disabled="disabled" href="#">Testing</a> The code snippet above appears ...

Header media query in CSS3 not functioning as expected

Currently, I have two separate style sheets for mobile and desktop versions. My intention is to default to the mobile style sheet. Upon examining my header, I have included the following: <link rel='stylesheet' media='all' href=&ap ...