简体   繁体   English

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

[英]Styling PHP Output with an External Stylesheet

I know that this question has been asked in abundance, however, I am too novice to grasp the general gist of other threads;我知道已经有很多人问过这个问题,但是,我太菜了,无法掌握其他线程的一般要点; hence me asking my own question that is specific to my own code.因此我问了我自己的特定于我自己的代码的问题。

I would like to style the text that my PHP form gives the user following their submission of the form, be it the style of the text, background, layout, etc. through an external CSS.我想在用户提交表单后设置我的 PHP 表单为用户提供的文本的样式,无论是文本的样式、背景、布局等,都是通过外部 CSS。

My current PHP is this:我目前的 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;
?>

Simply add classes to your HTML elements - even though you're dynamically outputting the HTML from PHP the same styling rules apply.只需将类添加到您的 HTML 元素 - 即使您从 PHP 动态输出 HTML,同样的样式规则也适用。 You have a class applied to the containing DIV, so you can style the child elements like so:您有一个应用于包含 DIV 的类,因此您可以设置子元素的样式,如下所示:

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

You can write your styling into a .css file then include it in the <head>...</head> section:您可以将样式写入 .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