[英]Overriding media queries for particular width - CSS
我创建了Responsive 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文件中覆盖这些值。
我试图用Google搜索,但是我得到的只是关于媒体查询的优先级,而与覆盖无关。
编辑:我已经使用子主题的.info文件添加了新的CSS文件。 以下是各个.info文件的内容。 我遵循了drupal文档来创建子主题。 但是,我真的不觉得这在Drupal的体系结构中是个问题,但是重写CSS Media查询可能必须以不同的方式完成,得出此结论的原因是因为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文件中。
如果要通过drupal_add_css添加此CSS
drupal_add_css('/path/to/css.css',array('weight'=>'9999',));
使css文件与父主题完全相同。
如果问题仍然存在,请禁用CSS缓存-清除缓存,然后再检查一次。
另一选择查看您是否在子主题的.info文件或各种import语句中准确提及子主题路径。
有一个技巧,您可以使用这种替代。
例如。 您有一个基本主题,文件base/css/donotwant.css
,在子主题的.info
文件中,您必须指定stylesheets[all][] = donotwant.css
并将其神奇地排除在外。
之后,您可以按照所需的方式在子主题中编码样式。
我的错! 还有一个额外的“;” 在媒体查询的开头。 因此,没有执行媒体查询替代。 显然是一个额外的“;” 我猜大概是CSS的结尾,不知道为什么从来没有考虑过其余的CSS!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.