繁体   English   中英

如何在中间对齐标题?

[英]How to align the title in the middle?

我正在使用codepen.io,正在创建一个段落。 该图具有标题。

问题是我希望标题居中对齐。它应该自动将标题设置在中间,而不是编辑“ x”的值。 我无法使用CSS来做到这一点,而且我相信javascript可以胜任。

这是我用来绘制标题的一个函数,下面是指向我项目的链接。

var text = document.createElementNS(svgNS,"text");
    text.setAttributeNS(null, 'x', 100);
    text.setAttributeNS(null, 'y', 15);
    text.textContent = (titel); 
document.getElementById("bargraph").appendChild(text);

完整代码:

codepen.io/Cleanwater/pen/LWQyJm?editors=0010

var text = document.createElementNS(svgNS,"text");
    text.setAttributeNS(null, 'y', 15);
    text.textContent = (titel); 
document.getElementById("bargraph").appendChild(text);
    text.setAttributeNS(null, 'x', 300 / 2 - text.getBBox().width /2);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM