Search code examples
phpstylesheet

Specifying a php include to use a certain stylesheet?


I am dividing my website in the typical php include way. If I want the includes to use their own stylesheet how is this done? For example if I have include "header.php", how can I make it so that a stylesheet only applies to this include?


Solution

  • You can do this either by including a different stylesheet to begin with, or by giving your <body> element an id or class attribute that enables you to write selectors such as

    body#header {
        /* ... */
    }
    

    The first approach plugs in at the <head> tag render code, the second does so at the <body> tag render code. You need to write your code such that one of these places also knows which PHP script you intend to include (or have already included).