简体   繁体   English

如何在React的同一行中显示两个单词?

[英]How can I make two words appear in the same line in React?

I had this code before: 我之前有以下代码:

projectName: project.get('name') === 'default' ? 'No Project' : project.get('name')

And in the render() method I had this: 在render()方法中,我有这个:

<div className='c-card__projects'>
  Project: {card.projectName}
</div>

and It looked like this in the UI 在用户界面中看起来像这样

在此处输入图片说明

Now I changed the code to take into account the color of the project like this: 现在,我更改了代码以考虑项目的颜色,如下所示:

  projectName: <div style={{color: project.get('color')}}>
    {project.get('name') === 'default' ? 'No Project' : project.get('name')}
  </div>

And now it looks like this: 现在看起来像这样:

在此处输入图片说明

How can I do to be display in the same line as before, instead of two lines (I just wanted to change the color)? 如何显示在以前的同一行而不是两行(我只是想更改颜色)?

Try changing to a span for inline styling. 尝试更改为跨度以进行内联样式。

projectName: 
<span style={{color: project.get('color')}}>
    {project.get('name') === 'default' ? 'No Project' : project.get('name')}
</span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让这两个组件出现在同一行? (文本框 label 和文本框) - how to make these two components appear on the same line? (textbox label and the textbox) 如何使复选标记出现在同一行中的input元素之后? - How can I make the check sign appear after the input element in the same line? 如何使此下拉菜单与其父级显示在同一行? - How can I make this dropdown menu appear on the same line as its parent? React Native - 如何在两个单词之间创建动态虚线(引线)? - React Native - How can I create a dynamic dotted line (leader) between two words? 如何将两个单词统计为同一行中的1 - How to count two words as 1 in same line 如何使两个输入框在相同的Enter击键下做出反应? - How can I make two input boxes react at the same enter keystroke? 如何使Types中的单词显示为Chips? - How do i make the words at Types appear as Chips? 当数据相同时,如何使绘图线显示在折线图上? - How to make plotline appear on line chart when data is same highcharts? 如何使输入+文本可通过同一行单击/显示为列表 - How to make an input + text clickable through the same line/appear as a list 什么时候可以在react / react中使用reactDOM /如何使某些东西出现在屏幕上而不是在consoke中? - When can you use reactDOM in react/how can i make something appear on screen rather than in consoke?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM