HTML:更改文本字符串中特定词的颜色 [英] HTML: Changing colors of specific words in a string of text
问题描述
我有以下讯息(稍有改动):
在2011年1月30日之前进入比赛,
$$$$ - 包括惊人的夏季旅行!
我目前有:
< p style =font-size:14px; color:#538b01; font-weight:bold; font-style:italic;&
格式化文本字符串,但要将2011年1月30日的颜色更改为#FF0000和summer到#0000A0。
如何严格使用HTML或内联CSS?
pre> < p style =font-size:14px; color:#538b01; font-weight:bold; font-style:italic;&
由
输入比赛< span style =color:#ff0000> 2011年1月30日< / span>
,您可以赢得$$$$ - 包括令人惊叹的
< span style =color:#0000a0>夏天< / span>
旅行!
< / p>
或者您可能希望使用CSS类:
< html>
< head>
< style type =text / css>
p {
font-size:14px;
color:#538b01;
font-weight:bold;
font-style:italic;
}
.date {
color:#ff0000;
}
.season {/ * OK,有点设计... * /
color:#0000a0;
}
< / style>
< / head>
< body>
< p>
由
输入比赛< span class =date> 2011年1月30日< / span>
,你可以赢得$$$$ - 包括惊人的
< span class =season>夏天< / span>
旅行!
< / p>
< / body>
< / html>
I have the below message (slightly changed):
"Enter the competition by January 30, 2011 and you could win up to $$$$ — including amazing summer trips!"
I currently have:
<p style="font-size:14px; color:#538b01; font-weight:bold; font-style:italic;">
formatting the text string, but want to change the color of "January 30, 2011" to #FF0000 and "summer" to #0000A0.
How do I do this strictly with HTML or inline CSS?
<p style="font-size:14px; color:#538b01; font-weight:bold; font-style:italic;">
Enter the competition by
<span style="color: #ff0000">January 30, 2011</span>
and you could win up to $$$$ — including amazing
<span style="color: #0000a0">summer</span>
trips!
</p>
Or you may want to use CSS classes instead:
<html>
<head>
<style type="text/css">
p {
font-size:14px;
color:#538b01;
font-weight:bold;
font-style:italic;
}
.date {
color: #ff0000;
}
.season { /* OK, a bit contrived... */
color: #0000a0;
}
</style>
</head>
<body>
<p>
Enter the competition by
<span class="date">January 30, 2011</span>
and you could win up to $$$$ — including amazing
<span class="season">summer</span>
trips!
</p>
</body>
</html>
这篇关于HTML:更改文本字符串中特定词的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!