【问题标题】:Can I implement Html-Code as Css-Content?我可以将 Html-Code 实现为 Css-Content 吗?
【发布时间】:2019-12-15 12:27:57
【问题描述】:

如何让变量$text 显示为 HTML?

请看下面的代码示例:

<?php
  header('Content-type: text/css');
  $background = "#ffafff";
  $color = "#000000";
  $green = "#16a86f";
  $text= '<h1>TestText</h1>';
?>
body {
  background-color: <?=$background?>;
}
#logo::before{content: "<?php echo($text);?>";}
#logo {
  color: <?=$green?>;
  font-weight: bold;
}
#slogan {
   color: <?=$color?>;
}
#rahmen {
  border: 0.1em solid <?=$green?>;
  text-align: center;
}

目前我得到这个输出:

【问题讨论】:

  • 我不确定我是否理解您的问题,您是在问如何显示变量$text 吗?
  • 无法在css中输出htmlcontent!

标签: php html css


【解决方案1】:

content 内不能有 HTML 标签:

$text = '<h1>TestText</h1>';

因此,将其更改为仅包含 TestText,然后使用 CSS 为元素设置样式以匹配 h1 的样式。

#logo::before {
  font-size: 1.5em;
  font-weight: bold;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-29
    • 1970-01-01
    • 2023-01-20
    • 1970-01-01
    相关资源
    最近更新 更多