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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13583833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:06:45  来源:igfitidea点击:

How to change font color mid-sentence

htmlcss

提问by dugla

What is the correct way to change the color or font face for a single word or set of words within a sentence? I am using Twitter Bootstrap and want to inherit all the attributes of the <div>'s class, but only tweak them slightly.

更改句子中单个单词或一组单词的颜色或字体的正确方法是什么?我正在使用 Twitter Bootstrap 并希望继承<div>'s 类的所有属性,但只稍微调整它们。

回答by Jason Towne

Going off of Chordscomment, you can create a <span>tag that surrounds the text you want to change. You can easily add multiple classes to a single span to achieve just the look you want as well.

除了Chords评论之外,您可以创建一个<span>围绕要更改的文本的标签。您可以轻松地将多个类添加到单个跨度,以实现您想要的外观。

Here's a fiddleto show how you can use multiple classes on a single span.

这是一个展示如何在单个跨度上使用多个类的小提琴

CSS

CSS

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

HTML

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