SVG drop shadow using css3

后端 未结 7 1620
谎友^
谎友^ 2020-11-22 12:34

Is it possible to set drop shadow for an svg element using css3 , something like

box-shadow: -5px -5px 5px #888;
-webkit-box-shadow: -5px -5px 5px #888;
         


        
7条回答
  •  独厮守ぢ
    2020-11-22 13:27

    Probably an evolution, it appears that inline css filters works nicely on elements, in a certain way.

    Declaring a drop-shadow css filter, in an svg element, in both a class or inline does NOT works, as specified earlier.

    But, at least in Firefox, with the following wizardry:

    Appending the filter declaration inline, with javascript, after DOM load.

    // Does not works, with regular dynamic css styling:
    
    shadow0.oninput = () => {
      rect1.style.filter = "filter:drop-shadow(0 0 " + shadow0.value + "rem black);"
    }
    
    // Okay! Inline styling, appending.
    
    shadow1.oninput = () => {
      rect1.style += " ;filter:drop-shadow(0 0 " + shadow1.value + "rem black);"
      rect2.style += " ;filter:drop-shadow(0 0 " + shadow1.value + "rem black);"
    }

    Firefox only

    Does not works! | Okay!

提交回复
热议问题