【问题标题】:Using css pseudo element in php doesn´t work在 php 中使用 css 伪元素不起作用
【发布时间】:2020-03-09 02:30:57
【问题描述】:

我的问题是我必须在 php 中添加标签,以便在其中放置一些带有伪元素 span: before 和 content: 'text' 的样式,其中我有多种语言的翻译。

当然,已经添加,并且文件上的其余特殊字符正确显示。我的问题只是 .我还尝试了“header('Content-Type:text/html; charset = utf-8');”没有任何变化。

问题是没有正确读取特殊字符为“í”或“ç”,甚至添加了utf8_decode。

这里是我已经声明要翻译的单词的php代码

$textoProtecciones = utf8_decode ($trEstatico->_("Protecciones"));
$textoCaracteristicas = utf8_decode ($trEstatico->_("Características"));
$textoCortes_Negativo = utf8_decode ($trEstatico->_("Negativo"));

这里是php中一个标签中的css样式


<style>
    @media (max-width: 768px) {


        #owlcomparativatable .owl-item.active.center  .item-table .clear.clear_third span:before {
            content: '<?php echo $textoProtecciones;?>';
        }

        #owlcomparativatable .owl-item.active.center  .item-table .clear.clear_fourth span:before {
            content: '<?php echo $textoCaracteristicas;?>';
        }

        #owlcomparativatable .owl-item.active.center  ul.cortes li.features_tablet:first-child span:before {
            content: '<?php echo $textoCortes_Negativo;?>';
        }
</style>

但是,即使所有内容都已正确声明,我仍会在屏幕上看到“Características”。即使在控制台代码中也没有正确读取“í”的 utf8 代码,显示如下:

#owlcomparativatable .owl-item.active.center .item-table .clear.clear_fourth span:before {
content: 'Caracter&iacute;sticas';
}

有人可以帮我解决这个问题吗?

【问题讨论】:

  • 您是否在 html 模板的头部设置了&lt;meta charset="UTF-8"&gt;?
  • UTF-8 all the way through的可能重复
  • 当然, 已添加。其实其余的特殊字符都显示正确,只是php中中的这句话内容显示不正确。

标签: php html css pseudo-element css-content


【解决方案1】:

&amp;iacute; 是í 的HTML 实体。其中的所有字符(与号、i、a 等)都以 ASCII 格式出现,因此无需(或点)对字符编码进行任何操作。

HTML 实体在 CSS 中没有特殊含义,因此文本“按原样”显示。

您需要将 HTML 转换为纯 (UTF-8) 文本。使用the html_entity_decode function。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    相关资源
    最近更新 更多