所以我从MySQL数据库中提取usename和msg,并希望更改用户名和消息的颜色。
echo "<span class='uname'>" . $extract['username'] . "</span>: <span class='msg'>" . $extract['msg'] . "</span><br>";
答案 0 :(得分:2)
echo "<span class='uname' style='color: green'>" . $extract['username'] . "</span>: <span class='msg' style='color: blue'>" . $extract['msg'] . "</span><br>";
答案 1 :(得分:1)
最好将CSS样式应用于已有的类,使用传统方式的样式表,而不是使用内联样式,这是非常规的。虽然,内联方法更容易。您不会在PHP中更改事物的颜色,而是在CSS中执行。选择您想要的颜色,获取它们的十六进制代码,然后根据您想要设置用户名和信息的样式,将它们设置为颜色或背景颜色属性。
.uname{
color: #3d3; /* hex values representing Red, Green, Blue */
}
.msg{
color: #900; /* shorthand for #990000, represents a red hue */
}
如果您无法访问该页面的样式表,则可以在内部/页内“样式表”中添加style
标记,例如:把它放在文件的头部:
<style type="text/css">
.uname{
color: #3d3; /* hex values representing Red, Green, Blue */
}
.msg{
color: #900; /* shorthand for #990000, represents a red hue */
}
</style>
示例:
.uname, .msg{
color: #d0d; /* red + blue = some shade of purple */
background-color: #000; /*red 0, green 0, blue 0 = no color = black*/
}
<span class='uname'>" . $extract['username'] . "</span>: <span class='msg'>" . $extract['msg'] . "</span><br>