如何在句子中间更改字体颜色

21
什么是在句子中更改单个单词或一组单词的颜色或字体的正确方法?我正在使用Twitter Bootstrap,并希望继承
类的所有属性,但仅略微调整它们。
1个回答

33

按照Chords的评论所说,您可以创建一个<span>标签来包围您想要更改的文本。 您可以轻松地将多个类添加到单个以实现所需的外观。

这里是一个示例,展示了如何在单个上使用多个类。

CSS

.bold { font-weight: bold; }
.red { color: #FF0000; }
.yellow-background { background-color: Yellow; }​

HTML

Here is <span class="bold">some text</span> that we are going to apply 
<span class="bold red">different styles</span> to. You can see how 
<span class="bold yellow-background">multiple classes</span> can be used to 
change the <span class="red bold yellow-background">look and feel</span> 
of the text.​

太棒了!这正是我想要的。我会把这个给Jason,但是感谢Chords提出这种方法。干杯。 - dugla
1
刚刚发现了这个,简直不敢相信以前居然没想到。 - Steve Reeder

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接