Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要在我的globalStyles.css文件中使用php块_Php_Css - Fatal编程技术网

需要在我的globalStyles.css文件中使用php块

需要在我的globalStyles.css文件中使用php块,php,css,Php,Css,我的globalStyles.css已经稳定了3周,并且在项目中随处可见。在研究了几个SO帖子和回复之后,似乎有些人喜欢将他们的全局CSS内容放在一个.php文件中,以避免我遇到的问题 问题就在这里 在我的项目文件的顶部有一个PHP块——这是我的index.PHP的顶部: <?php include 'titleBar.php'; require_once 'navBar.php'; require_once 'theDatabase.php'; // funct

我的globalStyles.css已经稳定了3周,并且在项目中随处可见。在研究了几个SO帖子和回复之后,似乎有些人喜欢将他们的全局CSS内容放在一个.php文件中,以避免我遇到的问题

问题就在这里

在我的项目文件的顶部有一个PHP块——这是我的index.PHP的顶部:

  <?php
   include 'titleBar.php';

   require_once 'navBar.php';

   require_once 'theDatabase.php'; // functions for the UI and DB access

   require_once 'globals.php'; // variables and statics used throughout
  ?>
('Artifacks'是项目名称。非常好,我没有选择它。)

然后我到处都使用$sitePath,例如:

 <img src="<?php echo $sitePath?>images/Artifacks-icon.png"></img>
background-image: url('<?php echo $sitePath; ?>images/egypt-Sphinx.jpg );
如果您使用此链接(正如您编写的那样)链接到样式表:

<link rel="stylesheet" type="text/css" href="<?php echo $sitePath ?>globalStyles.css" />
这就是CSS的工作原理。该CSS文件中的所有URL都是相对于CSS文件本身的

<sitepath> globalStyles.css
<sitepath> images/egypt-Sphinx.jpg
globalStyles.css
图片/埃及-Sphinx.jpg

如果您需要在样式表中运行php,那么这应该会有所帮助


你必须稍微改变一下结构。将globalstyles更改为php文件,并在链接行中调用它,如下所示:
我必须在这一行中给你+1!这解决了这个特殊情况,尽管cale_b提出了一个通用的解决方案,从现在开始我将使用它。这两种解决方案就像爱因斯坦的狭义相对论和广义相对论——谢谢哈克雷!注意使用PHP提供CSS。这可能会有更多的负面影响,你可以在开始时看到,这似乎是惊人的。尽可能长时间地坚持使用静态CSS文件。如果你不能做到这一点,那么你的设计通常都会有缺陷,因此即使这样,最好还是再看两次。cale_b这以一种创造性的方式解决了我不知道自己遇到的问题-与.php文件不同,在一个.css文件中,我不能只是开始使用不同的脚本语言——从现在起,我将按照您在这里概述的内容来构造我的外部.css文件。对于可能隐藏站点资产的嵌套子文件夹,您在这里的技术似乎可以奏效——谢谢。现在我必须弄清楚这两种选择中的哪一种。同时这里有一个+1。
  .grayDecorative
   {
      background-image: url('<?php echo $sitePath; ?>images/egypt-Sphinx.jpg ) ;
      /* other styles here.........*/
   }
    http://localhost/Artifacks/
<link rel="stylesheet" type="text/css" href="<?php echo $sitePath ?>globalStyles.css" />
background-image: url('<?php echo $sitePath; ?>images/egypt-Sphinx.jpg ) ;
background-image: url("images/egypt-Sphinx.jpg") ...
<sitepath> globalStyles.css
<sitepath> images/egypt-Sphinx.jpg
<?php
    header("Content-Type: text/css");
    header("Vary: Accept");
?>
background-image: url('<?php echo $sitePath; ?>images/egypt-Sphinx.jpg );