Siddharth Thevaril
Siddharth Thevaril

Reputation: 3788

Link multiple php files to a single stylesheet?

I'm making a simple website with 3 pages in php. The main page is index.php and the other two can be opened through index.php via links.
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. Do I have to put link tags in all php files to refer to the stylesheet? Is there any other way possible?

Upvotes: 1

Views: 1554

Answers (3)

Narendrasingh Sisodia
Narendrasingh Sisodia

Reputation: 21437

If you had header/top.php then copy all those files within your top.php as like

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

and you can use top.php within your each php file just by adding

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

Upvotes: 2

Raja Sekar
Raja Sekar

Reputation: 2130

If you have three different pages and linking all the css file in index.php, It will not get reflected in all the pages.

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

  2. Separate css file for each page.

  3. You can go for single page application. but you have to do some magics using JS

Now the choice is yours!!

Upvotes: 2

Adrian Cid Almaguer
Adrian Cid Almaguer

Reputation: 7791

You can do one page named includes.php put into all yours files include and include this page in all your pages

Upvotes: 1

Related Questions