【发布时间】:2016-01-25 21:43:03
【问题描述】:
以下文件是显示 3 个灯的正在进行的工作,我试图在每个灯中显示水平和垂直居中的文本。我不确定发生了什么,但只出现了 lamp3 的文本,而且它不在正确的位置。其他灯根本不显示文字。
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" id="root">
<defs>
<linearGradient y2="0" id="lamp2rim" x1="0" x2="1" y1="0">
<stop offset="0" stop-color="#bfbfbf"/>
<stop offset="1" stop-color="#404040"/>
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp2cap" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.992188" stop-color="#00ff00"/>
<stop offset="1" stop-opacity="0.988281" stop-color="#018201"/>
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp2spec" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.996094" stop-color="#ffffff"/>
<stop offset="0.703125" stop-opacity="0.984375" stop-color="#06d306"/>
</linearGradient>
<linearGradient y2="0" id="lamp3rim" x1="0" x2="1" y1="0">
<stop offset="0" stop-color="#bfbfbf"/>
<stop offset="1" stop-color="#404040"/>
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp3cap" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.992188" stop-color="#00ff00"/>
<stop offset="1" stop-opacity="0.988281" stop-color="#018201"/>
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp3spec" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.996094" stop-color="#ffffff"/>
<stop offset="0.703125" stop-opacity="0.984375" stop-color="#06d306"/>
</linearGradient>
<linearGradient y2="0" id="lamp1rim" x1="0" x2="1" y1="0">
<stop offset="0" stop-color="#bfbfbf"/>
<stop offset="1" stop-color="#404040"/>
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp1cap" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.992188" stop-color="#00ff00"/>
<stop offset="1" stop-opacity="0.988281" stop-color="#018201"/>
</linearGradient>
<linearGradient spreadMethod="pad" y2="1" id="lamp1spec" x1="0" x2="1" y1="0">
<stop offset="0" stop-opacity="0.996094" stop-color="#ffffff"/>
<stop offset="0.703125" stop-opacity="0.984375" stop-color="#06d306"/>
</linearGradient>
</defs>
<g id="lamp2" transform="translate(15.0,0.0) scale(0.25)">
<title>Lamp 2</title>
<circle stroke-linecap="round" transform="rotate(90 320 240)" fill="#212121" r="167" cx="320" id="lamp2svg_3" cy="240" stroke-width="17.5"/>
<circle stroke-linecap="round" fill-opacity="0.64" fill="url(#lamp2rim)" r="160" cx="319.252837" id="lamp2svg_7" cy="239.999045" stroke-width="17.5"/>
<circle stroke-linecap="round" fill="url(#lamp2cap)" r="150" cx="320.000535" id="lamp2svg_8" cy="240.001698" stroke-width="17.5"/>
<text text-anchor="middle" x="0" y="0" font-size="55" font-family="Verdana" fill="blue">CCC</text>
<ellipse stroke-linecap="round" transform="rotate(-47.7626 249.18 168.124)" fill="url(#lamp2spec)" rx="75.675959" cx="249.179609" ry="44.402987" cy="168.124194" stroke-width="17.5"/>
</g>
<g id="lamp3" transform="translate(100.0,82.0) scale(0.25)">
<title>Lamp 3</title>
<circle stroke-linecap="round" transform="rotate(90 320 240)" fill="#212121" r="167" cx="320" id="lamp3svg_3" cy="240" stroke-width="17.5"/>
<circle stroke-linecap="round" fill-opacity="0.64" fill="url(#lamp3rim)" r="160" cx="319.252837" id="lamp3svg_7" cy="239.999045" stroke-width="17.5"/>
<circle stroke-linecap="round" fill="url(#lamp3cap)" r="150" cx="320.000535" id="lamp3svg_8" cy="240.001698" stroke-width="17.5"/>
<text text-anchor="middle" x="0" y="0" font-size="55" font-family="Verdana" fill="blue">EEE</text>
<ellipse stroke-linecap="round" transform="rotate(-47.7626 249.18 168.124)" fill="url(#lamp3spec)" rx="75.675959" cx="249.179609" ry="44.402987" cy="168.124194" stroke-width="17.5"/>
</g>
<g id="lamp1" transform="translate(100.0,0.0) scale(0.25)">
<title>Lamp 1</title>
<circle stroke-linecap="round" transform="rotate(90 320 240)" fill="#212121" r="167" cx="320" id="lamp1svg_3" cy="240" stroke-width="17.5"/>
<circle stroke-linecap="round" fill-opacity="0.64" fill="url(#lamp1rim)" r="160" cx="319.252837" id="lamp1svg_7" cy="239.999045" stroke-width="17.5"/>
<circle stroke-linecap="round" fill="url(#lamp1cap)" r="150" cx="320.000535" id="lamp1svg_8" cy="240.001698" stroke-width="17.5"/>
<text text-anchor="middle" x="0" y="0" font-size="55" font-family="Verdana" fill="blue">AAA</text>
<ellipse stroke-linecap="round" transform="rotate(-47.7626 249.18 168.124)" fill="url(#lamp1spec)" rx="75.675959" cx="249.179609" ry="44.402987" cy="168.124194" stroke-width="17.5"/>
</g>
</svg>
我真的很想要一种优雅的方式将父组中的文本居中。
JSFiddle:https://jsfiddle.net/8kouys3w/6/
【问题讨论】: