javascript - whiteSpace writing interline style in react does not take effect
漂亮男人
漂亮男人 2017-05-16 13:27:38
0
3
595

Adding inline styles to elements in react will take effect on everything else except whiteSpace. Is there any way to solve it? The purpose is to use

when text overflows.
 <span style={{
    fontSize: '14px',
    paddingTop: '1px',
    fontFamily: '微软雅黑',
    maxWidth: '56px',
    overflow: 'hidden',
    textOverflow: 'ellipsis',
    whiteSpace: 'nowrap'
 }}>
    {node.title}
  </span>

The style displayed in the browser is

element.style {
    font-size: 14px;
    padding-top: 1px;
    font-family: 微软雅黑;
    max-width: 56px;
    overflow: hidden;
    text-overflow: ellipsis;
}

Kneel down and ask for advice, thank you for your guidance

漂亮男人
漂亮男人

reply all(3)
Ty80

display: inline-block;

phpcn_u1582

Because it is an iframe style, you can only write inline styles. But after trying many methods, white-space:nowrap cannot be used.
Including upgrading to the latest react version.
The final solution is:

 <span style={{
    fontSize: '14px',
    paddingTop: '1px',
    fontFamily: '微软雅黑',
    maxWidth: '56px',
    overflow: 'hidden',
    textOverflow: 'ellipsis',
    whiteSpace: 'pre'
 }}>
    {node.title}
  </span>

I don’t know why the nowrap attribute cannot be used, but using the pre attribute solves the problem perfectly.

淡淡烟草味

https://github.com/facebook/r...

nowrap was deprecated in HTML4 and is not a part of HTML5.
I strongly suggest using CSS instead.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!