HTML:更改文本字符串中特定单词的颜色

新手上路,请多包涵

我有以下消息(略有更改):

“在 2011 年 1 月 30 日之前参加比赛,您可能会赢取高达 $$$$ 的奖金——包括精彩的夏季旅行!”

我目前有:

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

格式化文本字符串,但想将“January 30, 2011”的颜色更改为#FF0000,将“summer”的颜色更改为#0000A0。

我如何严格地使用 HTML 或内联 CSS 来做到这一点?

原文由 Mitch 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 269
1 个回答
<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>

原文由 Jacob 发布,翻译遵循 CC BY-SA 2.5 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题