简体   繁体   English

将多个php文件链接到一个样式表?

[英]Link multiple php files to a single stylesheet?

I'm making a simple website with 3 pages in php. 我正在用php创建一个包含3页的简单网站。 The main page is index.php and the other two can be opened through index.php via links. 主页是index.php ,另外两个可以通过链接通过index.php打开。
The link to CSS is given in the index.php file and I want the CSS to get applied to all the other files as well. index.php文件中提供了CSS的链接,我也希望CSS也适用于所有其他文件。 Do I have to put link tags in all php files to refer to the stylesheet? 我是否必须在所有php文件中放置链接标记以引用样式表? Is there any other way possible? 还有其他办法吗?

If you have three different pages and linking all the css file in index.php, It will not get reflected in all the pages. 如果您有三个不同的页面并链接了index.php中的所有css文件,它将不会在所有页面中得到体现。

So better you can follow any of the three approach, 因此最好您可以采用以下三种方法中的任何一种,

  1. Put all the css file in one php file, say styles.php and link it in all the pages 将所有css文件放在一个php文件中,说styles.php并将其链接到所有页面

  2. Separate css file for each page. 每个页面使用单独的CSS文件。

  3. You can go for single page application . 您可以申请单页申请 but you have to do some magics using JS 但是您必须使用JS做一些魔术

Now the choice is yours!! 现在的选择是您的!!

If you had header/top.php then copy all those files within your top.php as like 如果你有header/top.php那么所有这些文件复制你的内top.php

<link rel="stylesheet" href="style.css"/>...

and you can use top.php within your each php file just by adding 您可以在每个php文件中使用top.php,只需添加

<?php include 'pathtocss/top.php'?>

您可以将一个名为includes.php的页面放入所有文件中,并将该页面包含在所有页面中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM