13

How do you declare the background of an svg script image to be transparent?

1
  • Please be more specific. In what kind of document is it inserted? What's the parent element? What is an "svg script image"? Commented Jun 23, 2011 at 5:38

2 Answers 2

9

If you're viewing in a browser then the background should be transparent automatically. At least it is in FF4 and the latest version of Chrome, but not in some older browsers (e.g. http://petercollingridge.co.uk/data-visualisation/mouseover-effects-svgs).

If you want the background to be semi-transparent then fill the space with a <rect> and set its opacity to a number between 0 and less than 1.

2

Even easier method is to delete all the data that is used in the file content.

For example, this is the file content before any change.

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="24.000000pt" height="24.000000pt" viewBox="0 0 24.000000 24.000000" preserveAspectRatio="xMidYMid meet">

After, the file content will be the following one.

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg>
  <g transform="translate(0.000000,24.000000) scale(0.100000,-0.100000)" fill="#ff0000" stroke="none">
    <path d=""/>
  </g>
</svg>


Not the answer you're looking for? Browse other questions tagged or ask your own question.