简体   繁体   English

覆盖特定宽度的媒体查询-CSS

[英]Overriding media queries for particular width - CSS

I have created a sub-theme of Responsive Bartik and I need to reduce the width of sidebars without touching the original theme: 我创建了Responsive Bartik的子主题,我需要在不触及原始主题的情况下减小边栏的宽度:

Original: 原版的:

@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 in sub-theme: 子主题中的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;
    }
}

To my surprise the original CSS is taking effect. 令我惊讶的是,原始CSS生效了。 Except for the media queries any other css properties I am able to override. 除了媒体查询之外,我还可以覆盖其他任何CSS属性。 If I change 25% to 18% and -100% to -92% in the original css file itself I am getting the desired result, but I am not able to figure out how to override these values in another css file. 如果我将原始css文件本身的25%更改为18%,将-100%更改为-92%,则可以得到理想的结果,但是我无法弄清楚如何在另一个css文件中覆盖这些值。

I tried to google but all I am getting is regarding the priorities in media queries but nothing regarding overriding. 我试图用Google搜索,但是我得到的只是关于媒体查询的优先级,而与覆盖无关。

Edit: I have added the new CSS file using .info file of the sub-theme. 编辑:我已经使用子主题的.info文件添加了新的CSS文件。 Below are the contents of respective .info file. 以下是各个.info文件的内容。 I have followed a drupal documentation to create sub-theme. 我遵循了drupal文档来创建子主题。 However, I dont really feel this is a problem in Drupal's architecture but overriding CSS Media query has to be done in a different way probably, the reason for this conclusion is because any other css attributes in custom.css file are being rendered with exception of overridden media query. 但是,我真的不觉得这在Drupal的体系结构中是个问题,但是重写CSS Media查询可能必须以不同的方式完成,得出此结论的原因是因为custom.css文件中的任何其他css属性都被渲染,但覆盖的媒体查询。

Original: 原版的:

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"

Sub-theme: 子主题:

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"

The only difference is the addition of line - 唯一的区别是添加了行-

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

in sub-theme's .info file. 在子主题的.info文件中。

  1. If you are adding this css through drupal_add_css 如果要通过drupal_add_css添加此CSS

    drupal_add_css( '/path/to/css.css', array( 'weight' => '9999', ) ); drupal_add_css('/path/to/css.css',array('weight'=>'9999',));

  2. Keep css file exactly same as the parent theme. 使css文件与父主题完全相同。

  3. If still problem persists then please disable CSS caching - clear the cache and check it one more time. 如果问题仍然存在,请禁用CSS缓存-清除缓存,然后再检查一次。

  4. Another option See if you are exactly mentioning sub-theme path in sub-theme's .info file or in the various import statements. 另一选择查看您是否在子主题的.info文件或各种import语句中准确提及子主题路径。

There is a trick, that you can use for this kind of overrides. 有一个技巧,您可以使用这种替代。

Eg. 例如。 you have a base theme, with a file base/css/donotwant.css , in your child theme's .info file you have to specify stylesheets[all][] = donotwant.css and it will be magically excluded. 您有一个基本主题,文件base/css/donotwant.css ,在子主题的.info文件中,您必须指定stylesheets[all][] = donotwant.css并将其神奇地排除在外。

After that, you can code the styling in a way you want in your child theme. 之后,您可以按照所需的方式在子主题中编码样式。

My bad! 我的错! There was an extra ';' 还有一个额外的“;” at the beginning of the media query. 在媒体查询的开头。 Due to this only media query overrides were not being executed. 因此,没有执行媒体查询替代。 Apparently an extra ';' 显然是一个额外的“;” would probably mean the end of css I guess, do not know why rest of the css was never considered! 我猜大概是CSS的结尾,不知道为什么从来没有考虑过其余的CSS!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM