Drupal7:将文件名从template.php传递到css文件的头部背景随机化



我的风景:我安装了带有Omega主题的Drupal 7。

我的问题是:我必须为css(节头(的特定区域设置一个随机背景。由于响应式设计,我有4个分离的css文件,文件名相同,但唯一的区别是_mobile_narrow_normal_wide后缀。我在css文件中用一些简单的行设置了背景:

#section-header {
  background: url(../images/sf_header_wide.jpg) no-repeat top center;
  height: 390px;
  margin: 0;
  padding: 0;  
}

我需要为背景添加多个图像,我想知道是否有可能从外部源导入文件名(例如我的template.php文件(,并在不向template.php文件添加背景行的情况下获得类似的内容,因为我已经为响应设计分离了css文件

#section-header {
      background: url("../images/<?php echo $fileimage; ?>_wide") no-repeat;
      height: 390px;
      margin: 0;
      padding: 0;  
    }

有可能得到我需要的东西吗?

我不建议这样做,因为web浏览器将缓存您的CSS文件,所以如果您希望每次都更改,它就不会更改。除此之外,这不是一种正常的做法,

不过,你也可以做一些事情。一个是在页眉本身,只需像一样生成样式表

<head>
<link rel="stylesheet" type="text/css" href="primaryStyleSheet.css" media="screen" />
[...]All other head stuff, imports, responsive style sheet stuff here
<style>
/* Define this style AFTER the other CSS files are imported to be sure it loads */
#section-header {
  background: url("../images/<?php echo $fileimage; ?>_wide") no-repeat;
  height: 390px;
  margin: 0;
  padding: 0;  
}
</style>
</head>

此外,您可以将!important添加到每个CSS定义中(即height: 390px !important;(

最新更新