You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在HTML中为<strong>标签包裹的指定文字添加颜色(不使用CSS)?

解决方案

你可以通过两种直接内嵌的方式实现,无需外部或内部CSS样式表:

  • 使用行内style属性(推荐,符合现代HTML规范)
    直接在<strong>标签上添加style="color: red;"属性,就能让包裹的文字变成红色:

    <p>For appointment, please call Martin at <strong style="color: red;">xxx-xxx-xxxx</strong> or email at <strong style="color: red;">support@test.com.</strong></p>
    
  • 使用<font>标签(兼容旧浏览器,虽已废弃但仍被支持)
    在<strong>标签内部嵌套<font color="red">标签,也能达到效果:

    <p>For appointment, please call Martin at <strong><font color="red">xxx-xxx-xxxx</font></strong> or email at <strong><font color="red">support@test.com.</font></strong></p>
    

之前内嵌方式没生效,大概率是style属性的位置写错了,或者语法有误(比如漏写分号、引号不配对),按上面的写法就能解决问题。

内容的提问来源于stack exchange,提问作者marlon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 09:12:56