What is the proper location to store an external SVG file in order to be linked by CSS?

I'm currently facing an issue with referencing SVG filters from CSS, where both are external files.

While it works perfectly fine when the SVG filter defs are inline, I encounter problems when they are in an external file. I prefer not to have the SVG inline to prevent bloating the HTML file.

Based on information from this source, it should work if the svg originates from the "same origins" as the html. However, I'm unsure of what exactly qualifies as "same origins."

Here is my directory structure:

  • index.html
  • \css

I've tried the following methods without success:

  • Placing the svg file in the root directory along with index.html
  • Also in the css directory
  • Using path url(css/test.svg#LightItUp);
  • Embedding the css inline like so: #LightItUp {filter:url(css/test.svg#LightItUp);}

The SVG content:

<svg width="500" height="262" viewBox="0 0 200 150">
<defs> 
  <filter id="LightItUp" filterUnits="userSpaceOnUse" x="0" y="0" width="400" height="420">

  <!-- Apply a uniform blur of the alpha channel -->
  <feGaussianBlur in="SourceAlpha" stdDeviation="3" result="blur"/>
  </filter>
</defs>
</svg>

The CSS content:

.logo  { filter: url(test.svg#LightItUp); }

Any assistance on this matter would be highly appreciated.

Answer №1

Include it just like you would a regular image

<object data="your.svg" type="image/svg+xml">
  <img src="yourfallback.jpg" />
</object>

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

Ensure that all elements are consistently kept within a DIV container

In my experience with web development, one recurring challenge is ensuring that everything stays contained within a div element. I often encounter situations where multiple nested divs and content cause styling nightmares when elements bleed out of their d ...

I am looking to continuously update a div element on my website with data sourced from another site. My goal is to enable the div element to refresh automatically without

I am looking to continuously update the getPrice($url) function every 1 second without the need for manual page refresh. <?php ini_set('display_errors', '1'); Currently, the getPrice($url) function only refreshes when I manual ...

The nightmare of Parent-Child Inheritance in JQuery/CSS is a constant struggle

Having difficulty implementing specific JQuery effects into a Bootstrap framework due to its extensive CSS causing issues. Created a test file named testjquery.html connected to a stylesheet defining a hidden element and activating the fade in of this ele ...

Ways to reset a JQuery/JavaScript filter

I am currently working on a list of div items that are being filtered and sorted using JavaScript. Each item animates as it enters the screen, scaling up to its final size. However, when I apply filters using buttons, items that are already displayed do n ...

By employing the pseudo selector ::after, one can enhance the design

Trying to align 2 images next to each other, I am floating one left and the other right with the intention of clearing the float using the ::after pseudo selector. The surrounding text is expected to flow in between the images. I often struggle with maki ...

"Implement a feature that allows for infinite scrolling triggered by the height of

Looking for a unique solution to implement a load more or infinite scroll button that adjusts based on the height of a div. Imagine having a div with a height of 500px and content inside totaling 1000px. How can we display only the initial 500px of the div ...

Synchronize scrolling between two elements to create a dynamic user experience

I'm currently facing an unusual situation. Take a look at the following image: Link to image So, I have this ruler positioned at the top. To prevent it from scrolling off when I vertically scroll the content, I placed it outside the scrolling contai ...

Is it possible for IE7/8 to show position:relative elements in front of position:absolute ones?

The layout I have created utilizes absolute positioning and includes a CSS-based menu in the header section. It functions perfectly in Firefox, however, when viewed in Internet Explorer 7 and 8, the menu dropdowns are hidden by the content area. Unfortunat ...

Angular 7/8 now allows for empty strings in Template Driven Forms

I've encountered a problem with my form validation that allows empty strings. The required attribute works, but it still allows the user to input spaces. I came across a solution online which involves using ng-pattern with the pattern pattern=".*[^ ]. ...

Creating a "save as" button in HTML - a step by step guide

When browsing the internet, if you want to save an HTML page you are viewing, you typically go to the File menu and select Save As. Is it possible to add a small button at the bottom of an HTML page that performs the same action? Instead of navigating thr ...

Differences Between Bootstrap Source Code and Bootstrap CDN Link

I am in the process of updating the user interface for my website, utilizing Bootstrap 5.3. Initially, I utilized the CDN link provided in the official documentation. Recently, I acquired Bootstrap Studio as a tool to streamline the UI development process. ...

"Learn how to showcase a picture in full-screen mode when the webpage is opened

I recently came across a script on Stack Overflow that allows me to select an image at random from an array. The script can be found here: Script to display an image selected at random from an array on page load However, I want to take this concept furthe ...

Accessing a .mov File Online for Everyone

Looking for a way to host my lengthy .mov file on my own server but display it in a YouTube-style player that is compatible with all browsers. Any suggestions on how to achieve this easily? ...

Are there any tools available that can generate CSS code automatically

Our team offers a pre-set CSS file along with the HTML mock-up for partners to customize, such as changing colors and background images, to match their desired aesthetic. They then provide feedback on the modified CSS files back to us. However, we face a ...

Tips for showcasing two pieces of content next to each other across the entire webpage using a combination of Bootstrap, CSS, and Laravel

I am facing a challenge with displaying two contents side by side on a full page and stacking them vertically when the screen size is small (mobile). I have managed to achieve the side by side display on a full page, but they stack on top of each other on ...

Next.js is refusing to render an array of HTML elements

Consider this scenario where I have a block of code in TypeScript that attempts to create and display a list of elements. Here is a sample implementation: const MenuList = ():ReactElement => { const router = useRouter(), liElements:any = []; con ...

Animating the background of a div element using jQuery

I am facing an issue with the code snippet below that I have written. It doesn't seem to be working as expected and I'm curious if anyone knows why. The problem is that I have set a background color on the DIV, but when hovering over it, I want ...

Creating a grid layout by designing boxes using CSS and HTML

I'm in the process of creating a homepage and I'd like it to resemble this design: (not the best quality, but the software I used was subpar (I miss mspaint)) Originally, I used buttons which made linking and customization easy, but I encounter ...

React splits the page and interrupts the scroll event listener

For some reason, my webpage has been split by the React.js library. When attempting to scroll down while hovering over the top navigation menu, scrolling becomes impossible. However, scrolling works fine when done on any other part of the screen. I' ...

Designing a CSS dot leader on the top line against a intricate backdrop

I am looking to incorporate dot leaders after the first line of text using CSS so that it can be used over a texture or image background. Expected behavior: https://i.sstatic.net/6Jsrk.png I have come across a few implementations of dot leaders on the i ...