使用同一导航栏链接多个页面


Link multiple pages with the same navbar

最近我了解到可以在html中导入php文件。这意味着,如果我想制作一个导航栏,我需要用php编写它,并在稍后将其"包含"在我的html中

  1. 如何在php中编写html代码?

  2. 如何使用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 */
}

有很多基本的造型教程和指南可以帮助你开始设计导航栏。

如果你的意思是如何将HTML写入php文件,稍后将包括在内,这样你就可以像往常一样编写HTML,而不会在php文件中出现任何问题。

但如果你想把HTML写进php代码,你会这样做:

<?php
    echo "<div> Some content here </div>";
?>

你也可以像在基本HTML中那样使用你的样式(css),它会毫无问题地影响你包含的文件。

相关文章: