HTML:更改文本string中特定单词的颜色

我有下面的消息(稍作改动):

“2011年1月30日前参加比赛,你可以赢得$$$$–包括惊人的夏季旅行!”

我目前有:

<p style="font-size:14px; color:#538b01; font-weight:bold; font-style:italic;"> 

格式化文本string,但要将“2011年1月30日”的颜色更改为#FF0000,将“夏季”更改为#0000A0。

我如何严格使用HTML或内联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> 

或者您可能想要使用CSS类:

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

span元素是内联的,因此不会破坏段落的stream动,只有标签之间的样式。

您可以使用HTML5标记<mark>

 <p>Enter the competition by <mark class="red">January 30, 2011</mark> and you could win up to $$$$ — including amazing <mark class="blue">summer</mark> trips!</p> 

并在CSS中使用这个:

 p { font-size:14px; color:#538b01; font-weight:bold; font-style:italic; } mark.red { color:#ff0000; background: none; } mark.blue { color:#0000A0; background: none; } 

标记<mark>具有默认的背景颜色…至less在Chrome中。

使用跨度。 例如) <span style='color: #FF0000;'>January 30, 2011</span>

 <font color="red">This is some text!</font> 

当我只想把一个单词改成红色的时候,这对我来说是最好的。

你可以使用更长的boringer方式

 <p style="font-size:14px; color:#538b01; font-weight:bold; font-style:italic;">Enter the competition by</p><p style="font-size:14px; color:#ff00; font-weight:bold; font-style:italic;">summer</p> 

你也可以上课:

<span class="mychangecolor"> I am in yellow color!!!!!!</span>

然后在一个css文件中做:

 .mychangecolor{ color:#ff5 /* it changes to yellow */ } 

定制这个代码,但是你喜欢适合你的需求,你可以select文本? 在该段中是什么字体或风格,你需要!

 <head> <style> p{ color:#ff0000;font-family: "Times New Roman", Times, serif;} font{color:#000fff;background:#000000;font-size:225%;} b{color:green;} </style> </head> <body> <p>This is your <b>text. <font>Type</font></strong></b>what you like</p> </body>