【问题标题】:Overriding media queries for particular width - CSS覆盖特定宽度的媒体查询 - CSS
【发布时间】:2015-06-28 09:12:27
【问题描述】:

我创建了一个响应式 Bartik 的子主题,我需要在不触及原始主题的情况下减小侧边栏的宽度:

原文:

@media all and (min-width: 851px) {
.
.
.
  #sidebar-first {
    width: 25%;
    margin-left: -100%; /* LTR */
  }
  #sidebar-second {
    width: 25%;
    margin-left: -25%; /* LTR */
    clear: none;
  }
.
.
.
}

子主题中的 CSS:

/* Raj: To reduce the width of the sidebar: */
@media all and (min-width: 851px)
{
    #sidebar-first {
        width: 18% !important;
        margin-left: -92% !important; /* LTR */
    }
    #sidebar-second {
        width: 18%;
        margin-left: -32%; /* LTR */
        clear: none;
    }
}

令我惊讶的是,原来的 CSS 正在生效。除了媒体查询我可以覆盖的任何其他 css 属性。如果我在原始 css 文件本身中将 25% 更改为 18% 并将 -100% 更改为 -92%,我将获得所需的结果,但我无法弄清楚如何在另一个 css 文件中覆盖这些值。

我试图用谷歌搜索,但我得到的只是媒体查询中的优先级,而没有关于覆盖。

编辑: 我已经使用子主题的 .info 文件添加了新的 CSS 文件。以下是各个 .info 文件的内容。我遵循了一个drupal文档来创建子主题。但是,我真的不觉得这是 Drupal 架构中的问题,但是覆盖 CSS 媒体查询可能必须以不同的方式完成,这个结论的原因是因为 custom.css 文件中的任何其他 css 属性都在渲染,除了覆盖媒体查询。

原文:

name = Responsive Bartik Tiles
description = Tile based flexible, recolorable theme with many regions and a responsive, mobile-first layout.
version = VERSION
core = 7.x

stylesheets[all][] = css/layout.css
stylesheets[all][] = css/style.css
stylesheets[all][] = css/colors.css
stylesheets[print][] = css/print.css

scripts[] = js/collapsible-menu.js

regions[header] = Header
regions[help] = Help
regions[page_top] = Page top
regions[page_bottom] = Page bottom
regions[highlighted] = Highlighted

regions[featured] = Featured
regions[content] = Content
regions[sidebar_first] = Sidebar first
regions[sidebar_second] = Sidebar second

regions[triptych_first] = Triptych first
regions[triptych_middle] = Triptych middle
regions[triptych_last] = Triptych last

regions[footer_firstcolumn] = Footer first column
regions[footer_secondcolumn] = Footer second column
regions[footer_thirdcolumn] = Footer third column
regions[footer_fourthcolumn] = Footer fourth column
regions[footer] = Footer

settings[shortcut_module_link] = 0

; Information added by Drupal.org packaging script on 2014-10-15
version = "7.x-1.0"
core = "7.x"
project = "responsive_bartik_tiles"
datestamp = "1413392482"

子主题:

name = Indian Snakes Responsive Bartik Tiles
description = Indian Snakes Tile based flexible, recolorable theme with many regions and a responsive, mobile-first layout.
version = VERSION
core = 7.x

base theme = responsive_bartik_tiles

stylesheets[all][] = css/layout.css
stylesheets[all][] = css/style.css
stylesheets[all][] = css/colors.css
stylesheets[print][] = css/print.css
stylesheets[all][] = css/custom.css

scripts[] = js/collapsible-menu.js

regions[header] = Header
regions[help] = Help
regions[page_top] = Page top
regions[page_bottom] = Page bottom
regions[highlighted] = Highlighted

regions[featured] = Featured
regions[content] = Content
regions[sidebar_first] = Sidebar first
regions[sidebar_second] = Sidebar second

regions[triptych_first] = Triptych first
regions[triptych_middle] = Triptych middle
regions[triptych_last] = Triptych last

regions[footer_firstcolumn] = Footer first column
regions[footer_secondcolumn] = Footer second column
regions[footer_thirdcolumn] = Footer third column
regions[footer_fourthcolumn] = Footer fourth column
regions[footer] = Footer

settings[shortcut_module_link] = 0

; Information added by Drupal.org packaging script on 2014-10-15
version = "7.x-1.0"
core = "7.x"
project = "responsive_bartik_tiles"
datestamp = "1413392482"

唯一的区别是增加了一行-

stylesheets[all][] = css/custom.css

在子主题的 .info 文件中。

【问题讨论】:

  • 尝试在head标签<style>/* Raj: To reduce the width of the sidebar: */ @media all and (min-width: 851px)...</style>中添加CSS代码
  • 这意味着您的子主题的 CSS 媒体查询已加载之前父主题的 CSS。

标签: html css drupal drupal-theming


【解决方案1】:
  1. 如果你是通过 drupal_add_css

    添加这个 css

    drupal_add_css( '/path/to/css.css', 大批( '重量' => '9999', ) );

  2. 保持 css 文件与父主题完全相同。

  3. 如果问题仍然存在,请禁用 CSS 缓存 - 清除缓存并再次检查。

  4. 另一种选择 查看您是否在子主题的 .info 文件或各种 import 语句中准确提及子主题路径。

【讨论】:

  • 我已经编辑了问题,css文件是使用子主题的.info文件添加的。我已经尝试在测试之前清除缓存。请查看是否有其他替代选项。
【解决方案2】:

有一个技巧可以用于这种覆盖。

例如。你有一个基本主题,有一个文件base/css/donotwant.css,在你的子主题的.info文件中你必须指定stylesheets[all][] = donotwant.css,它会被神奇地排除在外。

之后,您可以在子主题中以您想要的方式对样式进行编码。

【讨论】:

  • 我本来想覆盖一个特定的类/ID。尽管您的解决方案很高兴知道,但这会完全丢弃父主题的 css。不过感谢您的技巧:)
【解决方案3】:

我的错!有一个额外的';'在媒体查询的开头。因此,只有媒体查询覆盖没有被执行。显然是一个额外的';'我猜这可能意味着 css 的结束,不知道为什么从未考虑过 css 的其余部分!

【讨论】:

    猜你喜欢
    • 2021-12-06
    • 2012-07-10
    • 1970-01-01
    • 2013-08-26
    • 2016-02-25
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 2015-05-01
    相关资源
    最近更新 更多