如何在一个语句中设置html中的不同颜色

如何在一个语句中设置html中的不同颜色,第1张

概述嗨,我想在一行中有不同颜色的文字怎么可能: <p style="color:#4C4C4C;font-weight:bold;font-family:Calibri;font-size:20"> My Name is: <"color:#FF0000;font-weight:bold;font-family:Tahoma;font-size:20"> Tintincute </p> 我想为T 嗨,我想在一行中有不同颜色的文字怎么可能:
<p > My name is:  <"color:#FF0000;Font-weight:bold;Font-family:Tahoma;Font-size:20"> Tintincute </p>

我想为Tintincute提供不同的颜色,但在一行中存在问题,这个名字在一个空格中消失了.

这是代码示例:

<p >All fIElds marked with   <>*</color> <>are required</p>

@Phil:我尝试使用代码,但它没有用.代码本身显示在页面上.这就是我做的方式:

<div >[+valIDationmessage+]</div>p.detail {color:#4C4C4C;Font-weight:bold;Font-family:Calibri;Font-size:20 }span.name {color:#FF0000;Font-weight:bold;Font-family:Tahoma;Font-size:20 }<p >My name is: <span >Tintincute</span> </p>
解决方法 你可以使用CSS为这个元素创建类.所以你有类似的东西
p.detail { color:#4C4C4C;Font-weight:bold;Font-family:Calibri;Font-size:20 }span.name { color:#FF0000;Font-weight:bold;Font-family:Tahoma;Font-size:20 }

然后你的HTML会读:

<p >My name is: <span >Tintinecute</span> </p>

它比内联样式表更整洁,更易于维护并提供更大的重用.

这是完整的HTML来展示我的意思:

<!DOCTYPE HTML PUBliC "-//W3C//DTD xhtml 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd"><HTML xmlns="http://www.w3.org/1999/xhtml">    <style type="text/CSS">    p.detail { color:#4C4C4C;Font-weight:bold;Font-family:Calibri;Font-size:20 }    span.name { color:#FF0000;Font-weight:bold;Font-family:Tahoma;Font-size:20 }    </style></head><body>    <p >My name is: <span >Tintinecute</span> </p></body></HTML>

你会看到我在标题中的样式标记中有样式表类,然后我只在代码中应用这些类,例如< p class =“detail”> ……< / p>.通过w3schools教程,它只需要几个小时,并且在设置HTML元素样式时真的会转过身来.如果将其剪切并粘贴到HTML文档中,则可以编辑样式并查看在浏览器中打开文件时它们具有的效果.像这样试验是一种很好的学习方法.

总结

以上是内存溢出为你收集整理的如何在一个语句中设置html中的不同颜色全部内容,希望文章能够帮你解决如何在一个语句中设置html中的不同颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1104862.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存