簡體   English   中英

使用外部樣式表設置 PHP 輸出樣式

[英]Styling PHP Output with an External Stylesheet

我知道已經有很多人問過這個問題,但是,我太菜了,無法掌握其他線程的一般要點; 因此我問了我自己的特定於我自己的代碼的問題。

我想在用戶提交表單后設置我的 PHP 表單為用戶提供的文本的樣式,無論是文本的樣式、背景、布局等,都是通過外部 CSS。

我目前的 PHP 是這樣的:

<?php
// pull out the values from the request stream sent by the form
// and store those values into memory variables

$email   = $_REQUEST['email'];
$webmail   = $_REQUEST['subject'];
$firstName    = $_REQUEST['Firstname'];
$lastName  = $_REQUEST['Lastname'];
$sex     = $_REQUEST['sex'];
$to = 'emailaddress@me.com';
$comment   =$_REQUEST['comment'];
$subject   =$_REQUEST['subject'];


$header    = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"';
$header   .= ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
$htmlhead  = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">';
$htmlhead .= '<head><title>Getting Student Info</title>';
$htmlhead .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>';
$htmlbody  = '<body>';

// use the variables that store the information sent from the form.
 mail($to, $subject,"You have received the following feedback:". $comment, "from " . $firstName . " " . $lastName, "From: $email");
$htmlbody .= '<div class="formSubmissionText">';
$htmlbody .= "<h1>Processing a form</h1>";
$htmlbody .= "<p>Thank you " . $firstName . " " . $lastName;
$htmlbody .= ". We've recieved an email from your email address: " . $email . ", and will be respond as soon as possible!</p>";
$htmlbody .= "</div></body></html>";

// use echo to write all the information out back to the browser
echo $header . $htmlhead . $htmlbody;
?>

只需將類添加到您的 HTML 元素 - 即使您從 PHP 動態輸出 HTML,同樣的樣式規則也適用。 您有一個應用於包含 DIV 的類,因此您可以設置子元素的樣式,如下所示:

/* The Container */
.formSubmissionText { background:#ff0000; }
/* The Heading */
.formSubmissionText h1 { font-weight:bold; }
/* The Paragraph */
.formSubmissionText p { fonr-size:24px; }

您可以將樣式寫入 .css 文件,然后將其包含在<head>...</head>部分中:

<link rel="stylesheet" type="text/css" href="/css/my-stylesheet.css"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM