【问题标题】:Drupal 7: Randomize header background passing file name from template.php to the css fileDrupal 7:随机化标头背景,将文件名从 template.php 传递到 css 文件
【发布时间】:2013-05-13 23:48:25
【问题描述】:

我的风景:我安装了带有 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;  
}

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

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

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

【问题讨论】:

    标签: php css variables header drupal-7


    【解决方案1】:

    我不建议这样做,因为 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>
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-19
      • 2019-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多