如何定位 "g" 元素 SVG
How to position a "g" element SVG
我有一个 SVG 元素,它是一个圆圈中的箭头:https://jsfiddle.net/seabon/806ew03a/
<svg version="1.1" id="layer" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="15 15 102 102" style="enable-background:new 0 0 132 132;" xml:space="preserve" data-link="go_down">
<g class="cross-circle">
<g class="go-clockwise">
<circle class="st0" cx="66" cy="66" r="43.7"/>
</g>
</g>
<g class="down">
<polyline class="st1" points="76.4,71 66,81.4 55.6,71 "/>
<line class="st1" x1="66" y1="81" x2="66" y2="47"/>
</g>
</svg>
我想用css翻译箭头位置。我尝试在带有 class "down" 的 g 元素上使用相对位置,但它不起作用。我试着放一个 foreignObject 但也不管用..有人知道吗?
您可以将 transform:translate()
规则添加到 CSS 样式表。这应该有效:
svg .down {
transform:translate(0,-4px);
transition:transform 0.3s;
}
svg:hover .down {
transform:translate(0,4px);
}
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
viewBox="15 15 102 102" width="200" height="200">
<g>
<g>
<circle class="st0" cx="66" cy="66" r="43.7" fill="#f00"/>
</g>
</g>
<g class="down">
<polyline points="76.4,71 66,81.4 55.6,71" fill="#fff"/>
<line x1="66" y1="81" x2="66" y2="47" stroke="#fff"/>
</g>
</svg>
我有一个 SVG 元素,它是一个圆圈中的箭头:https://jsfiddle.net/seabon/806ew03a/
<svg version="1.1" id="layer" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="15 15 102 102" style="enable-background:new 0 0 132 132;" xml:space="preserve" data-link="go_down">
<g class="cross-circle">
<g class="go-clockwise">
<circle class="st0" cx="66" cy="66" r="43.7"/>
</g>
</g>
<g class="down">
<polyline class="st1" points="76.4,71 66,81.4 55.6,71 "/>
<line class="st1" x1="66" y1="81" x2="66" y2="47"/>
</g>
</svg>
我想用css翻译箭头位置。我尝试在带有 class "down" 的 g 元素上使用相对位置,但它不起作用。我试着放一个 foreignObject 但也不管用..有人知道吗?
您可以将 transform:translate()
规则添加到 CSS 样式表。这应该有效:
svg .down {
transform:translate(0,-4px);
transition:transform 0.3s;
}
svg:hover .down {
transform:translate(0,4px);
}
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
viewBox="15 15 102 102" width="200" height="200">
<g>
<g>
<circle class="st0" cx="66" cy="66" r="43.7" fill="#f00"/>
</g>
</g>
<g class="down">
<polyline points="76.4,71 66,81.4 55.6,71" fill="#fff"/>
<line x1="66" y1="81" x2="66" y2="47" stroke="#fff"/>
</g>
</svg>