Applying css on SVG,used as object in html file -


hi trying hand on svg , new it.though landed situation want change css value , fill of svg file.but not working.

<html>  <head>      <meta charset='utf-8'>      <title>practice</title>  </head>  <body>      <style type="text/css">  	.cp2{display: none;}      .cloud:hover .cp2{	  		fill:#ffffff;  		stroke:#0fc5a5;  		stroke-dasharray:90;  		stroke-dashoffset:0;		  		-webkit-animation:dash 1s linear forwards;  		-o-animation:dash 1s linear forwards;  		-moz-animation:dash 1s linear forwards;  		animation:dash 1s linear forwards;  		pointer-events:all;  	}  	.cloud:hover .cp1{display: none;}          </style>      <h2>svg</h2>      <div class="cloud">         <object  width="40" height="35" type="image/svg+xml"  data="new.svg"></object>      </div>  </body>  </html>    <!-- , svg file name "new.svg" below-->    <svg  xmlns="http://www.w3.org/2000/svg"        xmlns:xlink="http://www.w3.org/1999/xlink" id="cc" class="cc" viewbox="0 0 120 120">       <path class="cp1" d="m19,18h6a4,4 0 0,1 2,14a4,4 0 0,1 6,10h6.71c7.37,7.69 9.5,6 12,6a5.5,5.5 0 0,1 17.5,11.5v12h19a3,3 0 0,1 22,15a3,3 0 0,1 19,18m19.35,10.03c18.67,6.59 15.64,4 12,4c9.11,4 6.6,5.64 5.35,8.03c2.34,8.36 0,10.9 0,14a6,6 0 0,0 6,20h19a5,5 0 0,0 24,15c24,12.36 21.95,10.22 19.35,10.03z" />	   	  <path class="cp2" d="m9,12c9.53,12.14 9.85,12.69 9.71,13.22l8.41,18.05c8.27,18.59 7.72,18.9 7.19,18.76c6.65,18.62 6.34,18.07 6.5,17.54l7.78,12.71c7.92,12.17 8.47,11.86 9,12m13,12c13.53,12.14 13.85,12.69 13.71,13.22l11.64,20.95c11.5,21.5 10.95,21.8 10.41,21.66c9.88,21.5 9.56,20.97 9.7,20.43l11.78,12.71c11.92,12.17 12.47,11.86 13,12m17,12c17.53,12.14 17.85,12.69 17.71,13.22l16.41,18.05c16.27,18.59 15.72,18.9 15.19,18.76c14.65,18.62 14.34,18.07 14.5,17.54l15.78,12.71c15.92,12.17 16.47,11.86 17,12m17,10v9a5,5 0 0,0 12,4c9.5,4 7.45,5.82 7.06,8.19c6.73,8.07 6.37,8 6,8a3,3 0 0,0 3,11c3,12.11 3.6,13.08 4.5,13.6v13.59c5,13.87 5.14,14.5 4.87,14.96c4.59,15.43 4,15.6 3.5,15.32v15.33c2,14.47 1,12.85 1,11a5,5 0 0,1 6,6c7,3.65 9.3,2 12,2c15.43,2 18.24,4.66 18.5,8.03l19,8a4,4 0 0,1 23,12c23,13.5 22.2,14.77 21,15.46v15.46c20.5,15.73 19.91,15.57 19.63,15.09c19.36,14.61 19.5,14 20,13.72v13.73c20.6,13.39 21,12.74 21,12a2,2 0 0,0 19,10h17z" />  </svg>

now want fill , stroke of svg file change on div (with class="cloud") hover.altough able same if directly apply style in svg file , hover svg changing color.please suggest if can without javascript.i want use css not javascript achieve this.

no can't it. css doesn't apply across document boundaries. can't style svg css in html.

however, if working single colour icons, can use special colour name currentcolor allows svg "inherit" current colour html.

html

<html> <head>     <meta charset='utf-8'>     <title>practice</title> </head> <body>     <style type="text/css">     .cloud {         color: blue;         width: 100px;         height: 100px;     }     .cloud:hover {           color: red;     }     .cloud use {        fill: currentcolor;     }     </style>     <h2>svg</h2>     <svg viewbox="0 0 30 30" class="cloud">        <use xlink:href="new.svg#cloudicon"/>     </svg> </body> </html> 

new.svg

<svg  xmlns="http://www.w3.org/2000/svg"       xmlns:xlink="http://www.w3.org/1999/xlink" id="cc" class="cc" viewbox="0 0 30 30">   <g id="cloudicon">     <path class="cp1" d="m19,18h6a4,4 0 0,1 2,14a4,4 0 0,1 6,10h6.71c7.37,7.69 9.5,6 12,6a5.5,5.5 0 0,1 17.5,11.5v12h19a3,3 0 0,1 22,15a3,3 0 0,1 19,18m19.35,10.03c18.67,6.59 15.64,4 12,4c9.11,4 6.6,5.64 5.35,8.03c2.34,8.36 0,10.9 0,14a6,6 0 0,0 6,20h19a5,5 0 0,0 24,15c24,12.36 21.95,10.22 19.35,10.03z" />       <path class="cp2" d="m9,12c9.53,12.14 9.85,12.69 9.71,13.22l8.41,18.05c8.27,18.59 7.72,18.9 7.19,18.76c6.65,18.62 6.34,18.07 6.5,17.54l7.78,12.71c7.92,12.17 8.47,11.86 9,12m13,12c13.53,12.14 13.85,12.69 13.71,13.22l11.64,20.95c11.5,21.5 10.95,21.8 10.41,21.66c9.88,21.5 9.56,20.97 9.7,20.43l11.78,12.71c11.92,12.17 12.47,11.86 13,12m17,12c17.53,12.14 17.85,12.69 17.71,13.22l16.41,18.05c16.27,18.59 15.72,18.9 15.19,18.76c14.65,18.62 14.34,18.07 14.5,17.54l15.78,12.71c15.92,12.17 16.47,11.86 17,12m17,10v9a5,5 0 0,0 12,4c9.5,4 7.45,5.82 7.06,8.19c6.73,8.07 6.37,8 6,8a3,3 0 0,0 3,11c3,12.11 3.6,13.08 4.5,13.6v13.59c5,13.87 5.14,14.5 4.87,14.96c4.59,15.43 4,15.6 3.5,15.32v15.33c2,14.47 1,12.85 1,11a5,5 0 0,1 6,6c7,3.65 9.3,2 12,2c15.43,2 18.24,4.66 18.5,8.03l19,8a4,4 0 0,1 23,12c23,13.5 22.2,14.77 21,15.46v15.46c20.5,15.73 19.91,15.57 19.63,15.09c19.36,14.61 19.5,14 20,13.72v13.73c20.6,13.39 21,12.74 21,12a2,2 0 0,0 19,10h17z" />   </g> </svg> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -