How do i add external css to a php file?

I’ve decided to create a php, where i’ll contain a header.php, content.php and a footer.php . The concent php will change depending on what i need the specific page to do. The header and footer php files will remain relatively the same since its going to be most likely similar across every page.

For the content.php, i will have some divs for some box layouts only. How do i add css to that file alone? I want css that proprietary only to that page. Every php file will have their own css if needed. I’m trying to add external css and not inline css inside the element tag like this:

Any idea?

EDIT EDIT EDIT
So further researching, i figured it out using this link that provided me with the answer both for css and javascript.

Question has being answered! Thanks

1 Like

Hi,
Glad you solved the problem, and thanks for telling.

Nice to link to your finding, but I rather have the answer posted here.

If you were a member at StackOverflow you would know that SO recommends their posters to not link to, but to cite other places in their posts so their users do not have to rely on other sites to understand/read your message.

So I’ll put an answer here anyway, so you don’t have to go to SO to read.

You link to the stylesheet in the html outputted by the php script, e.g.:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    <link href="/stylesheet.css" media="all" rel="stylesheet">
</head>
<body>
<?php include("header.php"); ?>
<?php include("content.php"); ?>
<?php include("footer.php"); ?>
</body>
</html>
2 Likes

If I understand you correctly, you want to do exactly as I do. Content changes depending on the page, but the template is the same.

I always create a variable for the content ($content_name) and then define the path to that content in my controller (index.php) for the specific page. Like this: $content_name = ‘/includes/ (path to the specific html file)’;

Looks like you beat me to it! I didn’t see your reply before I posted mine.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.