如何在 php 中更改颜色
How to change color in php
所以我正在从 MySQL 数据库中提取用户名和消息,并想更改用户名和消息的颜色。
echo "<span class='uname'>" . $extract['username'] . "</span>: <span class='msg'>" . $extract['msg'] . "</span><br>";
echo "<span class='uname' style='color: green'>" . $extract['username'] . "</span>: <span class='msg' style='color: blue'>" . $extract['msg'] . "</span><br>";
您最好将 CSS 样式应用于您已有的 类,以常规方式使用样式表,而不是使用非常规的内联样式。虽然,内联方法更容易。您不会在 PHP 中更改事物的颜色,而是在 CSS 中进行更改。选择你想要的颜色,获取它们的十六进制代码,然后根据你想要如何设置用户名和消息的样式将它们设置为颜色或背景颜色属性。
.uname{
color: #3d3; /* hex values representing Red, Green, Blue */
}
.msg{
color: #900; /* shorthand for #990000, represents a red hue */
}
如果您无权访问该页面的样式表,您可以使用 style
标记包含内部/页内 "stylesheet",例如把它放在文档的头部:
<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>
所以我正在从 MySQL 数据库中提取用户名和消息,并想更改用户名和消息的颜色。
echo "<span class='uname'>" . $extract['username'] . "</span>: <span class='msg'>" . $extract['msg'] . "</span><br>";
echo "<span class='uname' style='color: green'>" . $extract['username'] . "</span>: <span class='msg' style='color: blue'>" . $extract['msg'] . "</span><br>";
您最好将 CSS 样式应用于您已有的 类,以常规方式使用样式表,而不是使用非常规的内联样式。虽然,内联方法更容易。您不会在 PHP 中更改事物的颜色,而是在 CSS 中进行更改。选择你想要的颜色,获取它们的十六进制代码,然后根据你想要如何设置用户名和消息的样式将它们设置为颜色或背景颜色属性。
.uname{
color: #3d3; /* hex values representing Red, Green, Blue */
}
.msg{
color: #900; /* shorthand for #990000, represents a red hue */
}
如果您无权访问该页面的样式表,您可以使用 style
标记包含内部/页内 "stylesheet",例如把它放在文档的头部:
<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>