Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override CSS media queries

Tags:

I work with a page every day that uses CSS media queries I don't like; I'd rather use the full page (most of them are related to the Twitter Bootstrap menu collapsing when narrower than 768px).

Is there a way to override Bootstrap's media queries with CSS? Preferably without defining my own media queries to override all of the rules individually, as I feel like this would take a pretty long time.

Edit: I don't have control of the source code, otherwise I'd just kill the bootstrap-responsive code.

like image 518
Kevin Burke Avatar asked Jul 11 '12 03:07

Kevin Burke


People also ask

How do I override media queries in CSS?

To override a specific media query rule, append a new css rule after the one you want to override. For example, if the last css rule does not have a media query attached, it will override all previously declared media queries (presuming the same selectors).

Can media queries overriding each other?

When using the max width media query, order must be from largest to smallest. The opposite is true for min-width. You'll find a detailed explanation of this here. If you are loading external CSS files they may be overriding your file.

What is CSS override?

To override the CSS properties of a class using another class, we can use the ! important directive. In CSS, ! important means “this is important”, and the property:value pair that has this directive is always applied even if the other element has higher specificity.

Can you use media queries in CSS?

Using media queries. Media queries are commonly associated with CSS, but they can be used in HTML and JavaScript as well. There are a few ways we can use media queries directly in HTML.


1 Answers

Why wouldn't you remove them in the first place?

If you can't, you still can override a CSS declaration with rules:

  • that have the same selector priority and come after the MQ block
  • that have higher selector priority than the rule in the MQ block
  • that have !important between the value and the semi-colon
    /* 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; } 

In the previous example, any of the declaration outside the @media block will override the one inside, e.g. there are 3 reasons why value2 will be applied and not value1.

like image 163
FelipeAls Avatar answered Sep 18 '22 10:09

FelipeAls