【问题标题】:Change Header background based on category selected根据选择的类别更改标题背景
【发布时间】:2012-08-16 12:54:41
【问题描述】:

我需要能够在不同类别的 cubecart v5 上更改标题背景。

So When for example Category 1 is selected I need header background to change to cat1.jpg and for it to stay the same when a product is selected.这是每个类别都需要的。

这是类别网址的外观

index.php?_a=category&cat_id=1

这就是产品网址的外观

index.php?_a=product&product_id=1

任何帮助将不胜感激。

【问题讨论】:

    标签: php css background header


    【解决方案1】:

    这就是我将要这样做的方式,因此这可能无法完全满足您的需求:

    假设标题不是内容的一部分,它不应该是<img> 标签。我们应该在 <header><div id="header"> 元素上使用 CSS background 属性。

    所以,在你的模板中,你有你的标题,你确实创建了一个带有类别 ID 的 CSS 类。

    <div id="header" class="cubecart-category cubecart-category-<?php print $catID; ?>">
    

    如果打印出 cubecart-category-5,假设我们的 CSS 将如下所示:

    .cubecart-category {
        height: 100px;
        width: 980px;
        ...
        background: none no-repeat scroll 0 0 transparent;
    }
    .cubecart-category-5 {
        background-image: url(cat5.jgp);
    }
    .cubecart-category-6 {
        background-image: url(cat6.jgp);
    }
    

    然后您可以在 cubecart-category 类上放置一个默认图像并让它被覆盖。

    我知道这是一个通用的答案,但它对您有帮助吗?告诉我。

    【讨论】:

    • 我试图实现这一点,但没有任何建议。我可以提供你需要看的任何东西。感谢您的快速回复。
    • 这对你来说哪里失败了?
    • 它只是没有工作我使用你提供的代码会出现相同的标题背景图像。
    • 遗憾的是,我的回答本身并不是一个解决方案,它只是您如何实施它的一个示例。它需要调整。您的代码的相关部分是什么样的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-15
    • 2019-06-18
    • 2011-01-05
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多