PHP Echo文本颜色更改为$ Product ['title']和php中的String?

时间:2018-08-24 11:47:57

标签: php html session

我想用白色回显success_flash,但是我不能用$ product ['title']做到。

在下面的行中,我想用白色回显所有内容,但此行不起作用:

$_SESSION['success_flash'] = $product['title'].'<span style="color:white;text-align:center;"> has been added to your cart!</span>';

我也尝试过

$_SESSION['success_flash'] = '<span style="color:white;text-align:center;"> $product['title']</span>'. '<span style="color:white;text-align:center;"> has been added to your cart!</span>';

但这对我也不起作用。

2 个答案:

答案 0 :(得分:0)

您可以添加!important来强制覆盖先前的color值,尽管这可能不是最佳做法:

$_SESSION['success_flash'] = '
    <span style="color:white!important;text-align:center;">
        '.$product['title'].'
    </span>
    <span style="color:white!important;text-align:center;"> 
        has been added to your cart!
    </span>
';

答案 1 :(得分:0)

尝试

$_SESSION['success_flash'] = '<span style="color:white;text-align:center;">'. $product['title']. ' has been added to your cart!</span>';

$_SESSION['success_flash'] = '<span style="color:#FFFFFF;text-align:center;">'. $product['title']. ' has been added to your cart!</span>';

您可以添加背景色以检查是否可用,然后可以删除背景色

喜欢

$_SESSION['success_flash'] = '<span style="background-color:#FF0000; padding:5px; color:#FFFFFF;text-align:center;">'. $product['title'] . ' has been added to your cart!</span>';

或尝试使用如下的CSS类

<style>
.myspan {
    color: white;
    text-align:center;
}
</style>

$_SESSION['success_flash'] = '<span class="myspan">'. $product['title']. ' has been added to your cart!</span>';