我知道这个问题已经被问了很多,但是,我太新手了,无法掌握其他线程的一般要点;因此我问我自己的问题,这是特定于我自己的代码的。
我想通过外部 CSS 设置我的 PHP 表单在提交表单后为用户提供的文本样式,无论是文本样式、背景、布局等。
我目前的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"/>