html - 使用 css 更改 svg 文本定位
问题描述
出于某种原因,我无法使用 CSS 更改 Svg 文本标签 x 和 y 变量,即使它应该可以工作并且正在使用 Svg 和 . 如果我直接在 html 上添加 x 和 y 位置,它就可以工作。html:
<svg id="main">
<g id="g2">
<circle id="c2" class="resize"/>
<rect id="r2" class="resize"/>
<text id="t2" class="resize">texthing</text>
</g>
css
#t2{
x:250px;
y:150px;
}
解决方案
我已经使用这两种类型的解决方案来解决这个问题,但第一种解决方案对我来说是最好的,使用左上角
svg g #t2{
/*you can use top left right like the example below*/
top:100px;
left:200px;
}
<svg id="main">
<g id="g2">
<circle id="c2" class="resize"/>
<rect id="r2" class="resize"/>
<text id="t2" class="resize">texthing</text>
</g>
还有另一种方法是使用转换翻译,例如:
t2{变换:翻译(100px,100px)}
推荐阅读
- desktop - 站立式办公桌会自行移动?
- javascript - 逗号前的Javascript大写单词
- javascript - JS UDF 返回标准 SQL / BigQuery 的结构并创建两列
- php - PHP:如何在 CSS 中调用 php 变量?
- selenium - 如何检查元素是否被点击 - selenium
- python - `versioneer` 是否与`PyPI` 打包兼容?
- android - 我无法使用 FindViewById 找到元素
- apache-kafka - 无法访问 Pepperbox 或 kafkameter 中的 jmeter 变量
- symfony - symfony 4 使用服务设置全局设置以在 twig 中实现
- javascript - 如何从 php 服务器打印到 POS 打印机