html - 使用 CSS 防止 SVG 文本旋转

标签 html css svg

我创建了一个 SVG 圆圈,里面有文本元素。我想使用 CSS 变换旋转 SVG,但我不想旋转文本元素。

.progress {
webkit-transform: rotate(-90deg);
    transform: rotate(-90deg);
	}
.progress__value {
  stroke-dasharray: 339.292;
    stroke-dashoffset: 339.292;
}
<div class="demo">
    <svg class="progress" width="100px" height="100px" viewBox="0 0 120 120">
<text x="44" class="counter" y="66" fill="#262626" style="
    font-weight: 700; font-size: 16px;
">30%</text>
        <circle cx="60" cy="60" r="54" fill="none" stroke="#DDDDDD" stroke-width="12" />
        <circle class="progress__value"  cx="60" cy="60" r="54" fill="none" stroke="#262626" stroke-width="12" />
    </svg>
</div>

最佳答案

围绕要旋转的元素创建一个组。

旋转它们

将旋转中心调整到圆心以避免平移

.inner {
    transform-origin: 60px 60px;
    transform: rotate(-90deg);
}
.progress__value {
    stroke-dasharray: 339.292;
    stroke-dashoffset: 339.292;
}
<div class="demo">
    <svg class="progress" width="100px" height="100px" viewBox="0 0 120 120">
        <text x="44" class="counter" y="66" fill="#262626" style="
    font-weight: 700; font-size: 16px;
">30%</text>
        <g class="inner">
        <circle cx="60" cy="60" r="54" fill="none" stroke="#DDDDDD" stroke-width="12" />
        <circle class="progress__value"  cx="60" cy="60" r="54" fill="none" stroke="#262626" stroke-width="12" />
        </g>
    </svg>
</div>

关于html - 使用 CSS 防止 SVG 文本旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45380389/

相关文章:

html - 如何找到 xmlns 定义?

html - 嵌套的 div。根据顶部 div 大小自动设置底部 div 高度

css - 在 Microsoft 渐变中使用较少的变量

html - 删除移动设备 (css) 上多余的水平空白

javascript - 将 div 放在 svg 中

SVG 中的 CSS 属性命名空间选择器

html - 如何将 p 标签和 span 标签放在一行中

javascript - 使用 JQuery 删除文本并更改嵌入在 div 中的 div 中的 bgimage

svg - d3js 圆弧内对齐文本

html - 如何重置 <pre><code> 中的选项卡?