我每天都会使用一个页面,它使用了我不喜欢的CSS媒体查询;我更愿意使用整个页面(其中大部分与Twitter Bootstrap菜单在窄于768px时折叠有关)。
有没有一种方法可以用CSS覆盖Bootstrap的媒体查询?最好不要定义自己的媒体查询来逐个覆盖所有规则,因为我觉得这需要很长时间。
编辑: 我不能控制源代码,否则我就会删除bootstrap-responsive代码了。
我每天都会使用一个页面,它使用了我不喜欢的CSS媒体查询;我更愿意使用整个页面(其中大部分与Twitter Bootstrap菜单在窄于768px时折叠有关)。
有没有一种方法可以用CSS覆盖Bootstrap的媒体查询?最好不要定义自己的媒体查询来逐个覆盖所有规则,因为我觉得这需要很长时间。
编辑: 我不能控制源代码,否则我就会删除bootstrap-responsive代码了。
为什么你不在一开始就删除它们呢?
如果您不能删除它们,您仍然可以通过以下规则覆盖CSS声明:
!important
关键字的规则 /* one id, one class AND one element => higher priority */
#id element.class { property: value2; }
/* !important will nuke priorities. Same side effects as a nuke,
don't do that at home except if you've tried other methods */
#id .class { property: value2 !important; }
@media(blah) {
/* Overridden. Thrice. */
#id .class { property: value1; }
}
/* same selector, same everything except it comes after the one in @media?
Then the latter is applied.
Being in a @media doesn't give any more priority (but it won't be applied
everywhere, depending on "blah", that's the point of MQ) */
#id .class { property: value2; }
@media
块外部声明中的任何声明都会覆盖其中的声明,例如有三个原因导致应用value2而不是value1。我想要覆盖bootstrap的responsive.css。
我的网站有一半需要使用默认的responsive.css,而另一半由于一个媒体查询导致了错误的布局,所以我想要删除它。
根据我的研究,css不允许删除媒体查询。
因此,我将复制responsive.css并删除媒体查询。如果您无法访问源代码,则覆盖可能是唯一的选择。