像素被添加到内联字体粗细
Pixel is added to inline font-weight
在 javascript 中,我定义了一些内联样式,其中之一是字体粗细。不幸的是,它不起作用,因为 'px' 会自动添加到值的末尾,然后由于值不正确而无法呈现:
注意:我使用的是 react ,因此代码如下所示。
render: function() {
return (
<table>
<tbody>
<tr>
{
data.map(function(d, i) {
var style = {};
if (d.value === 'selected') {
style['color'] = '#FFFFFF';
style['font-size'] = '16px';
style['font-style'] = 'normal';
style['font-weight'] = '700';
style['text-transform'] = 'uppercase';
}else {
style['border'] = '2px solid #C9C9C9';
style['color'] = '#C9C9C9';
style['font-size'] = '12px';
style['font-style'] = 'normal';
style['font-weight'] = '400';
}
return (<td>
<div style={style}>
{d.value}
</div>
</td>);
})
}
</tr>
</tbody>
</table>
);
}
当我在 chrome 中检查它时,它显示:font-weight: 700px
并且它不起作用,因为 px
使值不正确。
根据 React 文档尝试使用 style['fontWeight']
而不是 style['font-weight']
here fontWeight 属性 不会获得自动 'px' 后缀。
在 javascript 中,我定义了一些内联样式,其中之一是字体粗细。不幸的是,它不起作用,因为 'px' 会自动添加到值的末尾,然后由于值不正确而无法呈现:
注意:我使用的是 react ,因此代码如下所示。
render: function() {
return (
<table>
<tbody>
<tr>
{
data.map(function(d, i) {
var style = {};
if (d.value === 'selected') {
style['color'] = '#FFFFFF';
style['font-size'] = '16px';
style['font-style'] = 'normal';
style['font-weight'] = '700';
style['text-transform'] = 'uppercase';
}else {
style['border'] = '2px solid #C9C9C9';
style['color'] = '#C9C9C9';
style['font-size'] = '12px';
style['font-style'] = 'normal';
style['font-weight'] = '400';
}
return (<td>
<div style={style}>
{d.value}
</div>
</td>);
})
}
</tr>
</tbody>
</table>
);
}
当我在 chrome 中检查它时,它显示:font-weight: 700px
并且它不起作用,因为 px
使值不正确。
根据 React 文档尝试使用 style['fontWeight']
而不是 style['font-weight']
here fontWeight 属性 不会获得自动 'px' 后缀。