Apply SVG Gradient filter to background image

Get Off My Lawn

I found this SVG code, and I was wondering how do I apply it to a background image?

<svg width="600px" height="600px" viewbox="0 0 600 600">
    <defs>
        <linearGradient id="alphaLinear">
            <stop offset="0%" stop-color="#FFFFFF" stop-opacity="0%" />
            <stop offset="100%" stop-color="#FFFFFF" stop-opacity="100%" />
        </linearGradient>

        <mask id="Mask">
            <rect x="0" y="0" width="600" height="600" fill="url(#alphaLinear)"  />
        </mask>
    </defs>

    <image xlink:href="/media/images/body-bg.jpg" width="600" height="600" x="0" y="0" preserveAspectRatio="xMinYMin meet" mask="url(#Mask)"/>
</svg>

In the <image> tag I replaced the href url with the image I want to use. I then call the svg from the css like so:

body{
     background: url('/media/images/gradient.svg') center top no-repeat;
}

Nothing seems to be happening, all I am getting is a white background.

Paul LeBeau

There are a few things wrong:

  1. For external files, you will need the xmlns and xmlns:xlink namespace declarations in the <svg> tag.

    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
         width="600px" height="600px" viewbox="0 0 600 600">
    
  2. viewbox should be viewBox

  3. SVG files used as an external image in <img> or as a background-image need to be self contained. They cannot refer to other external files as you are doing here.

    You can embed the external JPEG as a Data URI though if you want.

    <image xlink:href="data:image/jpeg;base64,...Base64 encoded JPEG data here..."> 
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Apply combination of background colour and image filter to a svg path

From Dev

Apply combination of background colour and image filter to a svg path

From Dev

Apply blur filter to certain area of svg image

From Dev

Apply gradient on the whole SVG

From Java

How to apply a CSS filter to a background image

From Dev

Apply gradient to all images that have inline background image url?

From Dev

SVG Image opacity gradient

From Dev

CSS : Background Image with Background Gradient

From Dev

How to Apply the background gradient of a JFrame

From Dev

How to apply SVG so that it works in IE background image

From Dev

How to apply SVG so that it works in IE background image

From Dev

Firefox: SVG background image with filter gets rasterized / blurry

From Dev

How to apply a gradient to an image in ImageMagick?

From Dev

Background-image gradient not working

From Dev

Linear gradient and background image on a button

From Dev

Create a gradient around a background image

From Dev

Background-image with gradient effect

From Dev

Css apply background on background image

From Dev

Apply image to button background

From Dev

SVG polyline gradient apply only to stroke

From Dev

Background-image with background-gradient

From Dev

CSS - Background gradient and background image sent to bottom

From Dev

How to apply background Gradient style css

From Dev

SVG as background image

From Dev

SVG as background image

From Dev

filling svg background with an image

From Dev

SVG gradient as polylines stroke background with absolute position

From Dev

Apply SVG filter to "fill" only

From Dev

Core Image Filter Background

Related Related

HotTag

Archive