这听起来像是一个简单的修复程序,但让我详细解释一下。
我有一个<input type="submit"/>
按钮,我正在尝试将箭头对齐按钮文本的右边(该文本已经居中)。
这是小提琴:http : //jsfiddle.net/s6rrzsa4/4/
现在要解决的问题:
<input>
改为<button>
代码,因为它来自CMS)。@felix解决方案很好。但是它具有将span元素附加到正文的缺点,以便计算文本的宽度。我们可以使用canvas来计算文本的宽度,但不会将其附加到DOM。
http://jsfiddle.net/s6rrzsa4/16/
var elem = $('input'),
cs = window.getComputedStyle(elem[0]),
context = document.createElement("canvas").getContext("2d"),
metrics, pos;
context.font = cs.fontSize + " " + cs.fontFamily;
metrics = context.measureText(elem[0].value.toUpperCase()),
pos = (elem.width() - metrics.width)/2 + 20;
elem.css('background-position','calc(100% - '+pos+'px) center');
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句