[英]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.