如何为不同的php包含文件链接不同的样式表 [英] How to link different style sheets for different php include files
问题描述
说出你的 about
页面有一个自定义的css文件需要你做这样的事情:
about.php
<?
$ css = array('path_to_css_file','path_to_another_css_file');
require_once('header.php'); // aka the top
?>
[关于页面内容到这里]
<?
require_once('footer.php'); // aka底部
?>
您的 header.php
文件可以这样做:
header.php
< html>
< head>
< title>< / title>
< link rel =stylesheettype =text / csshref =main_style_sheet.css/>
<?
if(isset($ css)&& is_array($ css))
foreach($ css as $ path)
printf('< link rel =stylesheettype = text / csshref =%s/>',$ path);
?>
< / head>
< body>
通过这种方式,您只需加载给定页面所需的内容。
So I'm dividing my index.php page into three sections: top, middle, bottom. The middle section will have different html php inlude pages and therefore will require different style sheets. Do I link the specific stylesheets in the individual php include pages, or in the index page? Because in the index page, the different style sheets don't seem to take effect, why is that?
Say your about
page has a custom css file it needs you could do something like this:
about.php
<?
$css = array('path_to_css_file', 'path_to_another_css_file');
require_once('header.php'); // aka the top
?>
[about page content goes here]
<?
require_once('footer.php'); // aka the bottom
?>
The in your header.php
file you could do this:
header.php
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="main_style_sheet.css" />
<?
if (isset($css) && is_array($css))
foreach ($css as $path)
printf('<link rel="stylesheet" type="text/css" href="%s" />', $path);
?>
</head>
<body>
This way you only load what you need for the given page.
这篇关于如何为不同的php包含文件链接不同的样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!