php - Drupal 7 : Randomize header background passing file name from template. php 到 css 文件

标签 php css variables header drupal-7

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

是否有可能获得我需要的东西?

最佳答案

我不建议这样做,因为网络浏览器会缓存您的 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;)

关于php - Drupal 7 : Randomize header background passing file name from template. php 到 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16532949/

相关文章:

php - PHP变量的永久存储?

c++ - 从 .dat 文件读取参数到 C++?

php - 运行命令行脚本时设置 PHP 环境变量

jquery - 仅将列表项附加到选定选项卡中的列表

php - 将字段从一个数据库复制到 MySQL 中的另一个数据库

javascript - 2 种颜色的 HTML 输入文本

css - Safari 5.1 将边距/填充推出超过 50+ 像素

C++ 成员变量

php - 为 EntityType 设置数据属性(Sonata Admin)

javascript - 如何在此 PHP 页面中用简单的 HTML 选择替换此价格 slider ?选择选项可以传递 2 个值(最低价格和最高价格)吗?