简体   繁体   中英

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?

you cannot bind css to a php-include. you respond to a browser with HTML-code. with php you may control which css(-file) will be included in the HTML finally. you may bind css to certain tags, or classes, or ids. but those are HTML-concepts and have no relation to PHP except for the fact that PHP will control the final HTML-code.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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