繁体   English   中英

Insert CSS into html header via php Function

[英]Insert CSS into html header via php Function

我可以创建挂钩来编辑网站的外观,但没有使用 php 的经验。 hooks 联机帮助页提供了以下示例:

survey_page_top()
{
    print '<div class="yellow">Special announcement text to display at the top of every survey.</div>';
}

现在,我要做的是将以下 CSS 插入此 function (function 在复制呈现页面之前执行),以便在复制呈现页面之前执行上面的打印元素并阻止选择和打印消息,而不是打印所有消息。 我在其他地方发现了这些 CSS 元素,但我不知道如何将它们放入 function 中,然后应用于最后一页:

<style type="text/css" media="print">
body {
    
     visibility: hidden; display: none }
</style>

body, html{
     -webkit-user-select: none;
     -moz-user-select: none;
     -ms-user-select: none;
     user-select: none;
}

您可以通过以下方式在 PHP 字符串中添加您的代码:

survey_page_top() {
    echo '<style type="text/css" media="print">
    body {
        visibility: hidden; display: none
    }
    body, html{
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    </style>';
}

In your php code, create a variable and then define the CSS style tag and css within the variable, there is no need to declare a function for this simple code, also the style tag goes within the head. 如果您还需要 function 代码,请使用 function 和 php 变量。

survey_page_top(){
  $cssStyle = '
    <style type="text/css" media="print">
        body {
            visibility: hidden; display: none
        }
        body, html{
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }
    </style>';
  return $cssStyle;
}

PHP 文件中的 HTML

<!--/ After the php that defines the variable /-->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
<?=survey_page_top()?>

<!--/ Or  /-->

<?php echo survey_page_top(); ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM