【发布时间】:2016-05-15 08:53:05
【问题描述】:
所以最近我了解到可以在 html 中导入 php 文件。所以这意味着如果我想制作一个导航栏,我需要用 php 编写它,然后在我的 html 中“包含”它。所以我的问题是:
如何在php中编写html代码?
如何使用 css 设置导航栏的样式?
为了澄清第二个问题,我的意思是在我将 php 文件包含到 html 后,css 是否仍然有效
【问题讨论】:
所以最近我了解到可以在 html 中导入 php 文件。所以这意味着如果我想制作一个导航栏,我需要用 php 编写它,然后在我的 html 中“包含”它。所以我的问题是:
如何在php中编写html代码?
如何使用 css 设置导航栏的样式?
为了澄清第二个问题,我的意思是在我将 php 文件包含到 html 后,css 是否仍然有效
【问题讨论】:
至于在php中输出HTML:
<?php
echo "<p class='myTest' id='myTag'>This is some text within HTML-tags</p>";
// Notice the use of "" and '', you do not wanna close the echo adding a class or such
?>
至于 CSS,首先在您的 HTML 文件中包含一个样式表(在 <head> 标记中):
<link rel="stylesheet" type="text/css" href="myStyle.css">
在 myStyle.css 中设置 HTML 样式:
p.myTest {
color: red;
/* All <p> tags content with the class myTest will be written in red */
}
如果您希望您的样式是特定于标签的:
p {
color: red;
/* All <p> tags content will be written in red */
}
或者您可能希望将其应用于唯一 ID:
#myTag {
color: red;
/* The content of the tag with the id "myTag" will be colored red,
given that color is a valid property for that specific tag */
}
有大量的 basic styling 教程和指南可帮助您开始设计导航栏。
【讨论】:
如果您的意思是如何将 HTML 写入 php 文件,该文件将在稍后包含,这样您就可以像往常一样编写 HTML,而不会在 php 文件中出现任何问题。
但是如果你想将 HTML 写入 php 代码,你会这样做:
<?php
echo "<div> Some content here </div>";
?>
您也可以像在基本 HTML 中一样使用您的样式 (css),它会毫无问题地影响您包含的文件。
【讨论】: