使用外部样式表设置PHP输出样式

时间:2016-03-21 13:09:51

标签: php html css forms styling

我知道这个问题已被大量提出,但是,我太新手无法掌握其他线索的一般要点;因此,我问自己的问题,这是我自己的代码所特有的。

我想通过外部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;
?>

1 个答案:

答案 0 :(得分:0)

只需向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"/>