如何为不同的php包含文件链接不同的样式表 [英] How to link different style sheets for different php include files

查看:183
本文介绍了如何为不同的php包含文件链接不同的样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我将我的index.php页面分成三部分:top,middle,bottom。中间部分将有不同的html php inlude页面,因此需要不同的样式表。我是否将单个php包含页面中的特定样式表链接到索引页面?因为在索引页面中,不同的样式表似乎不起作用,为什么呢?

解决方案

说出你的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆