javascript - How to change the attribute of subitem are used by `use` element? -




i learn svg. want change circle fill value of second use. how can it? attempt:

* {  	stroke: brown;  	stroke-width: 1;  	fill: none;  }    .canvas{  	border-color: green;  	border-style: solid;  	border-width: 1px;  }    .sun > circle{  	fill: yellow;  }    .hot-sun > circle {  	fill: red;  }
<?xml version='1.0'?>  <!doctype svg public '-//w3c//dtd svg 1.1//en' 'http://www.w3.org/graphics/svg/dtd/svg11.dtd'>  <?xml-stylesheet type='text/css' href='../css/index.css'?>  <svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='1400' height='1000' viewbox='0 0 1400 1000' class='canvas'>  	<title>svg learning</title>  	<desc>this sandbox</desc>  	<defs>   		<g id='foo' class='sun'>  			<rect x='0' y='0' width='50' height='50'/>  			<circle cx='25' cy='25' r='10'/>  		</g>  	</defs>  	<g id='dwg'>  		<use xlink:href='#foo' transform='translate(10 10)' />      <!-- here expected sun red...-->  		<use xlink:href='#foo' transform='translate(10 70)' class='hot-sun'/>  	</g>  </svg>

you cannot css-select sub-elements of use element, not part of dom. nonetheless, css-attributes use element can inherited. so, long not style referenced element defined in <defs>, styling of <use> prevail.

note there must not * { fill:...} rule. style defs > #foo > circle element, , take precedence on inheritance use element. why stroke of second sun remains brown, despite rule have defined paint green.

* {  	stroke: brown;  	stroke-width: 1;  }    #foo rect {  	fill: none;  }    .canvas{  	border-color: green;  	border-style: solid;  	border-width: 1px;  }    use {  	fill: yellow;  }    .hot-sun {  	fill: red;  	stroke: green  }
<?xml version='1.0'?>  <!doctype svg public '-//w3c//dtd svg 1.1//en' 'http://www.w3.org/graphics/svg/dtd/svg11.dtd'>  <?xml-stylesheet type='text/css' href='../css/index.css'?>  <svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='1400' height='1000' viewbox='0 0 1400 1000' class='canvas'>  	<title>svg learning</title>  	<desc>this sandbox</desc>  	<defs>   		<g id='foo' class='sun'>  			<rect x='0' y='0' width='50' height='50'/>  			<circle cx='25' cy='25' r='10'/>  		</g>  	</defs>  	<g id='dwg'>  		<use xlink:href='#foo' transform='translate(10 10)' />      <!-- here expected sun red...-->  		<use xlink:href='#foo' transform='translate(10 70)' class='hot-sun'/>  	</g>  </svg>





wiki

Comments

Popular posts from this blog

elasticsearch - what is the equivalent data type for geo_point in hibernate search? -

firebase - How to wait value in Ionic 2 -

Jenkins: find build number for git commit -