Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React span space in between text

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>
    )

span 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?

like image 621
Ashraf Avatar asked Jan 20 '26 13:01

Ashraf


1 Answers

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)
like image 185
Shubham Khatri Avatar answered Jan 23 '26 03:01

Shubham Khatri