javascript - React span space in between text - Stack Overflow

I'm trying to add a space between span and text in React but it seems it behaves differently in JS

I'm trying to add a space between span and text in React but it seems it behaves differently in JSX? here is the code

return(
    <div>
         <h1 className="navbar"> <span style={styles}> {timeOfDay} </span> 
          {`${firstName} ${lastName}`} It is currently {hours} clock</h1>
    </div>
    )

As you can see {timeOfDay} which is good night is sticking to the text, what im trying to do is have a space between them, how can i achieve that in React?

I'm trying to add a space between span and text in React but it seems it behaves differently in JSX? here is the code

return(
    <div>
         <h1 className="navbar"> <span style={styles}> {timeOfDay} </span> 
          {`${firstName} ${lastName}`} It is currently {hours} clock</h1>
    </div>
    )

As you can see {timeOfDay} which is good night is sticking to the text, what im trying to do is have a space between them, how can i achieve that in React?

Share Improve this question asked Feb 6, 2019 at 17:40 AshrafAshraf 651 silver badge9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

There are multiple ways to add space between elements in JSX

  1. Use &nbsp;
    return(
       <div>
         <h1 className="navbar"> <span style={styles}> {timeOfDay} </span> 
          &nbsp;{`${firstName} ${lastName}`} It is currently {hours} clock</h1>
      </div>
    )
  1. Use {' '}
    return(
       <div>
         <h1 className="navbar"> <span style={styles}> {timeOfDay} </span> 
          {` ${firstName} ${lastName}`} It is currently {hours} clock</h1>
      </div>
    )
  1. Use CSS(padding/margin to span)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745649477a4638173.html

相关推荐

  • javascript - React span space in between text - Stack Overflow

    I'm trying to add a space between span and text in React but it seems it behaves differently in JS

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信