PHP文本变量改变颜色

问题描述 投票:-1回答:2

如何解决$ var($ a $ b和$ c)中的变量是红色和其他文本(这是测试,是)是正常的黑色。 谢谢您的回答!

$a = 125;
$b = "My text";
$c = "is";

$var = "This is test $b is $c $a.";
echo '<div class="test">', $var,'</div>';

<style>
.test {
  color: #000000;
  z-index: 8;
  display: block;
  font-weight: normal;
  position:relative;
  left: -1255px;
  top: -345px;
  font-family: arial;
  font-size: 30px;
  max-width: 1450px;
}
</style>
html css
2个回答
2
投票

您可以将这些变量包装在元素中并设置样式。如果您只想要颜色,或者(我更喜欢)像<span>这样的更具描述性的元素,如果它会强调这些值的语义意义,那个元素可能只是<em>。无论您选择哪一个,一旦输出元素,您可以照常设置它们:

$a = 125;
$b = "My text";
$c = "is";

$var = "This is test <em>$b</em> is <em>$c</em> <em>$a</em>.";
echo '<div class="test">'.$var.'</div>';

请注意样式表中添加的.test em规则,以解决<em> div中所有(且仅限于).test元素的问题。

<style>
.test {
  color: #000000;
  z-index: 8;
  display: block;
  font-weight: normal;
  position:relative;
  left: -1255px;
  top: -345px;
  font-family: arial;
  font-size: 30px;
  max-width: 1450px;
}
.test em {
  color: red;
}
</style>

有关此元素的更多信息以及(仅)视觉和语义标记之间的一般区别,请参阅Mozilla上的<em>: The Emphasis element


-1
投票
$a = 125;
$b = "My text";
$c = "is";

$var = "This is test $b is $c $a.";
echo '<div class="test">', $var,'</div>';

echo '<style>
.test {
  color: #000000;
  z-index: 8;
  display: block;
  font-weight: normal;
  position:relative;
  left: -1255px;
  top: -345px;
  font-family: arial;
  font-size: 30px;
  max-width: 1450px;
}
</style>';
© www.soinside.com 2019 - 2024. All rights reserved.