【问题标题】:Styling PHP Output with an External Stylesheet使用外部样式表设置 PHP 输出样式
【发布时间】:2016-03-22 02:07:28
【问题描述】:

我知道这个问题已经问过很多了,但是,我太新手了,无法掌握其他线程的一般要点;因此我问了我自己的问题,该问题特定于我自己的代码。

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

【问题讨论】:

  • 您还没有准确描述您的问题是什么?运行代码时会发生什么?输出和你的目标有什么区别?
  • 我很感激您的回复,但由于我缺乏知识并且我目前“正在努力”,我不太明白这意味着什么,抱歉:/
  • 我希望能够连接我用于表单所在网站的外部样式表之一。但我不确定该怎么做。对于可能造成的混乱,我深表歉意。

标签: php html css forms styling


【解决方案1】:

只需将类添加到您的 HTML 元素 - 即使您从 PHP 动态输出 HTML,同样的样式规则也适用。您有一个应用于包含 DIV 的类,因此您可以像这样设置子元素的样式:

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

您可以将样式写入 .css 文件,然后将其包含在 &lt;head&gt;...&lt;/head&gt; 部分中:

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

【讨论】:

  • 啊,这听起来完全符合我的目标!因此,如果我要以您演示的方式链接我的样式表,我将如何将示例 div 应用于输出,例如文本颜色为红色,只是为了示例?
  • 我现在已成功链接样式表并将所有文本应用为红色,非常感谢您。如果我遇到任何其他问题,您会很乐意提供帮助吗?
  • .formSubmissionText {color: #ff0000;} - 我认为你应该阅读一下 CSS:w3schools.com/css
  • 如果您需要帮助,请回到 SO,许多友好的人很乐意提供帮助。哦,如果确实有帮助,请将答案标记为正确。
  • 非常感谢。如果我在这种情况下遇到进一步的问题,我会在这里发表评论。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-11
  • 2013-04-16
  • 2011-12-14
  • 2014-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多