将文本大小更改为 PHP 函数的结果字符串


Change the text size as resulting string a PHP function

我在CSS中有一个疑问,我有一个字符串,例如:R$3,055.00,想知道我如何到达单词的" R$",并且只让字体比单词的其余部分小。

我在PHP中有这个函数,它返回产品的价值:

  <?php echo $this->getPriceHtml($_product, true) ?>

现在我正在用这段代码处理她的 CSS::

.regular-price .price {
    color: #0075BD !important;
    font-size: 30px !important;
    font-weight: bold !important;
}
.price::before{
    content: 'R$';
    font-size: 0.7em;
}

正如其他答案所指出的,您需要将该字符串放入元素中,以便使用 CSS 定位它。假设R$纯粹是表示性的,那么我建议如下,使用::before伪元素来放置R$文本并适当地设置其样式:

span.price::before {
  content: 'R$';
  font-size: 0.7em;
}
<span class="price">3,055.00</span>

根据更新的问题,我建议(使用上面的CSS HTML):

<?php echo '<span class="price">' . str_replace('R$', '', $this->getPriceHtml($_product, true)) . '</span>'; ?>
// 'R$': the string we're looking to replace, the 'needle';
// '': the string we're looking to replace with;
// $this->getPriceHtml($_product, true): the string we're looking in,
// the 'haystack'

引用:

  • .CSS:
    • 兼容::before::after
    • CSS 伪元素,::before/::after .
    • 生成的内容、自动编号和列表:伪元素:before:after
  • .PHP:
    • str_replace() .

使用 eg. small

<style>
#price {font-size: 12px;}
#price small {font-size: 10px;}
</style>
<p id="price">
    <small>R$</small>3,055.00
</p>

您必须像这样更改 html 标记

<p class='price'><span>R$</span>3,055.00</p>

然后你可以像这样风格化:

.price{
   //Price style here
}
.price span{
  // Intro styles here like :
  font-size: 75%;
}

希望对您有所帮助