我有以下消息(略有改动):
“在2011年1月30日前参加比赛,你可以赢得比赛 $$$$ - 包括惊人的夏季旅行!“
我目前有:
<p style="font-size:14px; color:#538b01; font-weight:bold; font-style:italic;">
格式化文本字符串,但希望将“2011年1月30日”的颜色更改为#FF0000,将“summer”更改为#0000A0。
如何使用HTML或内联CSS严格执行此操作?
答案 0 :(得分:88)
<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>
答案 1 :(得分:35)
您可以使用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>
具有默认背景颜色...至少在Chrome中。
答案 2 :(得分:31)
<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元素是内联的,因此不会破坏段落的流程,只会在标记之间设置样式。
答案 3 :(得分:18)
使用跨度。 ex)<span style='color: #FF0000;'>January 30, 2011</span>
答案 4 :(得分:12)
<font color="red">This is some text!</font>
当我只想在一个句子中将一个单词改为红色时,这对我来说是最好的。
答案 5 :(得分:1)
根据您的需求定制此代码,您可以选择文字吗?在段落中你需要什么字体或样式!:
<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>
答案 6 :(得分:0)
你可以使用更长的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>
&#13;
你明白其余的
答案 7 :(得分:0)
你也可以上课:
<span class="mychangecolor"> I am in yellow color!!!!!!</span>
然后在css文件中执行:
.mychangecolor{ color:#ff5 /* it changes to yellow */ }
答案 8 :(得分:0)