Default background color of SVG root element

后端 未结 6 1131
一生所求
一生所求 2020-11-29 17:30

I\'d like to set a default background color for the entire SVG document, to red for example.

/*          


        
6条回答
  •  天命终不由人
    2020-11-29 18:17

    I'm currently working on a file like this:

    
    
    
    ...
    

    And I tried to put this into style.css:

    svg {
      background: #bf1f1f;
    }
    

    It's working on Chromium and Firefox, but I don't think that it's a good practice. EyeOfGnome image viewer doesn't render it, and Inkscape uses a special namespace to store such a background:

    
    
    

    Well, it seems that SVG root element is not part of paintable elements in SVG recommandations.

    So I'd suggest to use the "rect" solution provided by Robert Longson because I guess that it is not a simple "hack". It seems to be the standard way to set a background with SVG.

提交回复
热议问题