July 10, 201412 yr Hi, I am very new to php so sorry if this is a simple question. I'm not sure if I can explain it but I'll try my best. I basically have 2 php files with nothing in them but HTML code, one is called table.php and the other is called nav.php. When working on those php files I would obviously like to style them but how can include an external stylesheet?... if I link a stylesheet file in those php files called "main.css" it works. But then when I try and php include the table.php and nav.php in my main.php file it doesn't work, I think because it's linking path is wrong and not only that it then calls the same main.css file twice. I can always link to the main.css in my main.php file but then I lose the styling in table.php and nav.php!! so i guess my question is what is the best way to link a css file from a php document? and then when i php include them in my main.php file it only calls it once etc... -thanks for any help!!! Edited July 10, 201412 yr by NerdTech
July 10, 201412 yr Can you do something like this: <html> <head> <meta charset="UTF-8"> <title>main.php</title> <link rel="stylesheet" href="main.css"> </head> <body> <?php include 'nav.php' ?> <?php include 'table.php' ?> <!-- Carry on with the rest of the code here. --> </body> </html>
July 10, 201412 yr Like Mr Ben says above this is the method to include the files. Within the nav.php and table.php you shouldn't re-reference the style sheet and as you are including them within the main.php then you can just have HTML within the nav and table files. EG: <html> <head> <meta charset="UTF-8"> <title>main.php</title> <link rel="stylesheet" href="main.css"> </head> <body> <?php include 'nav.php' ?> <?php include 'table.php' ?> <!-- Carry on with the rest of the code here. --> </body> </html> Thanks Mr Ben. Then the nav.php and table.php look like: <ul> <li>item 1</li> <li>item 2</li> <li>item 3</li> <li>item 4</li> <li>item 5</li> <li>item 6</li> <li>item 7</li> <li>item 8</li> <li>item 9</li> <li>item 10</li> </ul> this code is then output within the <body> tags of main.php
July 22, 201412 yr Can you do something like this: <html> <head> <meta charset="UTF-8"> <title>main.php</title> <link rel="stylesheet" href="main.css"> </head> <body> <?php include 'nav.php' ?> <?php include 'table.php' ?> <!-- Carry on with the rest of the code here. --> </body> </html> That's what I'd do. You could use an absolute path though I suppose.
Create an account or sign in to comment