html - 显性基线在 Firefox 中不起作用

标签 html css svg alignment

考虑以下示例:

g {
  transform: translate(50px, 50px);
  dominant-baseline: central;
  text-anchor: middle;
}
<svg width="100" height="100">
  <g>
    <circle cx="0" cy="0" r="15" stroke="#000" fill="#ffffff" />
    <text x="0" y="0">A</text>
  </g>
</svg>

Chrome 通过在中间垂直对齐文本来尊重 dominant-baseline: central:

enter image description here

但是,Firefox 似乎并不尊重 dominant-baseline: central:

enter image description here

您将如何解决这个跨浏览器问题?

最佳答案

SVG 1.1 specification显性基线不是继承的属性。 SVG 2 改变了这样的东西 dominant-baseline is inherited . Firefox 仅在版本 70 中实现了该 SVG 2 功能。即在最初写这个问题之后。

同时简单地在文本元素上设置显性基线。

g {
  transform: translate(50px, 50px);
  text-anchor: middle;
}
text {
  dominant-baseline: middle;
}
<svg width="100" height="100">
  <g>
    <circle cx="0" cy="0" r="15" stroke="#000" fill="#ffffff" />
    <text x="0" y="0">A</text>
  </g>
</svg>

关于html - 显性基线在 Firefox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55797336/

相关文章:

javascript - $(window).resize 不工作

html - 完整的浏览器宽度条

css - 在纯色背景上添加透明渐变

html - IE对齐问题

javascript - 拉斐尔 Js : How to re-arrange the elements inside a raphael set in a curve path

jquery - 无法使此下拉菜单中的顶级类别变为横向。

javascript - 如何使用 Javascript +1 onClick

javascript - 一起使用 ReactJS 和 PaperJS 时 Canvas 元素不会调整大小

python - 无法使用 matplotlib 正确导出为 svg 和 pdf

javascript - SVG 模式,任何方式/黑客停止重复图像