[英]What is the proper way to make a paragraph with some words having different styles using CSS and javascript
I've a paragraph, with several long lines of texts. 我有一段,有几行长的文字。 I need to make some words into different style. 我需要把一些词变成不同的风格。 What would be the proper way to do it without creating too many tags? 不创建太多标签的正确方法是什么?
How about when using react-intl format message? 使用react-intl格式的消息怎么样?
<div className="main">
Select the Gear icon, and then choose Users > Manage users
</div>
.main {
font-size:14px;
}
I want to make words Gear, Users and Manage users, different style. 我想用不同的样式来表示Gear,Users和Manage users。
You can use one of the built-in tags to achieve this. 您可以使用内置标签之一来实现此目的。
<b>
- Bold text <b>
-粗体 <strong>
- Important text <strong>
-重要文本 <i>
- Italic text <i>
-斜体文字 <em>
- Emphasized text <em>
-强调文字 <mark>
- Marked text <mark>
-标记文字 <small>
- Small text <small>
-小文本 <del>
- Deleted text <del>
-删除的文字 <ins>
- Inserted text <ins>
-插入的文本 <sub>
- Subscript text <sub>
-下标文字 <sup>
- Superscript text <sup>
-上标文本 .main { font-size:14px; }
<div className="main"> Select the <b>Gear</b> icon, and then choose <b><i>Users</i></b> > <em><ins><sub>Manage users</sub></ins></em> </div>
Or you can use the span
tag to create inline elements in your text and then you can style them as you want. 或者,可以使用span
标签在文本中创建内联元素,然后可以根据需要设置样式。
.main { font-size:14px; } #gear { font-size: 1.1rem; color: red; font-weight: bold; } #users { font-size: 1.3rem; color: blue; text-decoration: underline; } #manage-users { font-size: 0.9rem; color: gray; text-decoration: overline; }
<div className="main"> Select the <span id="gear">Gear</span> icon, and then choose <span id="users">Users</span> > <span id="manage-users">Manage users</span> </div>
Update 更新资料
The code below is an example how to style each word differently when you use react-intl FormattedMessage
. 下面的代码是一个示例,当您使用react-intl FormattedMessage
时,如何为每个单词设置不同的样式。 StackBlitz link. StackBlitz链接。
render() {
const style = {
color: 'red',
fontWeight: 'bold'
}
return (
<div>
<p>
<FormattedMessage
id="userHint"
defaultMessage={`Select the {gear} icon, and then choose {users} > {manageUsers}`}
values={{
gear: <b>Gear</b>,
users: <i>Users</i>,
manageUsers: <span style={style}>Manage users</span>
}}
/>
</p>
</div>
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.