Home >Web Front-end >CSS Tutorial >Why Doesn't My SVG Data URL Background Image Display in Firefox?

Why Doesn't My SVG Data URL Background Image Display in Firefox?

Barbara Streisand
Barbara StreisandOriginal
2024-12-25 21:07:11255browse

Why Doesn't My SVG Data URL Background Image Display in Firefox?

SVG Data URL Background-Image Not Displaying in Firefox

When setting an SVG as a background-image using a data URL in a pseudo element, the image fails to appear in Firefox. This is because Firefox treats the '#' character in the URL as the beginning of a fragment identifier.

To resolve this issue, the data URL contents must be URL encoded. This involves converting any '#' characters to '#'. The modified CSS code below incorporates the URL encoding:

content: '';
position: absolute;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 12px;
background-image: url('data:image/svg+xml;utf8,%3Csvg version="1.1">

By URL encoding the data URL contents, Firefox correctly interprets the hash characters as part of the SVG data, allowing the image to be displayed as the background.

The above is the detailed content of Why Doesn't My SVG Data URL Background Image Display in Firefox?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn