How to link different style sheets for different php include files

泄露秘密 提交于 2019-12-12 05:10:06

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5347550/how-to-link-different-style-sheets-for-different-php-include-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!