如何解决$ 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>
您可以将这些变量包装在元素中并设置样式。如果您只想要颜色,或者(我更喜欢)像<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。
$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>';