Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding Bootstrap 3 Media Queries

How do you override a media query on Bootstrap 3?

For example, I have my custom style sheet and I want to override a media query that is min-width: 768px to a min-width: 1200px.

Every time I do that it doesn't apply the settings. However if I change that media query on Bootstrap's own css file, then it works!

For more clarification:

bootstrap.css:

@media (min-width: 768px) {
  .navbar-header {
    float: left;
  }
}

My custom.css:

@media (min-width: 1200px) {
 .navbar-header {
 float: left;
 }
}

Please help me out.

like image 742
Quentin Gérard Avatar asked Mar 30 '14 18:03

Quentin Gérard


People also ask

How to use override in Bootstrap media queries?

The standard format of the Bootstrap Media queries Using Override in the Bootstrap framework is @media (min-width: ~ breakpoint in pixels here ~) ~ some CSS rules to be applied ~ that narrows the CSS rules defined to a certain viewport size and yet ultimately the opposite query might be used just like

What is the default media query for Bootstrap?

Bootstrap mainly uses the following media query varies-- or breakpoints-- in source Sass data for design, grid program, and elements. // Extra small devices (portrait phones, less than 576px) // No media query since this is the default in Bootstrap // Small devices (landscape phones, 576px and up) @media (min-width: 576px) ...

What is Bootstrap 3?

Bootstrap 3 is a mobile-first front-end framework. I’ve included the correct order for the Media Queries below, but I’ve also included at the bottom of them the non-mobile first breakpoints in case some people aren’t used to the mobile-first methodology since technically both will work.

Why do we use media queries?

We use a handful of media queries for delivering different styles sheet to different devices, to create sensible breakpoints for our layouts and interfaces. These breakpoints are mostly based on minimum viewport widths and allow us to scale up elements as the viewport changes.


1 Answers

When you use bootstrap css, they have it defined as:

@media (min-width: 768px) {
  .navbar-header {
    float: left;
  }
}

So it will always apply that css rule when it is above or at that width of 768, even if you apply your rule of media 1200 after the fact. This is because you are never overriding the previous rule you are just adding a new breakpoint.

To override default bootstrap rule use something like:

@media (min-width: 768px) {
  .navbar-header {
    float: none;
  }
}

In your own custom.css file, (Of course make sure to include your custom.css file after bootstrap.css to make custom load last).

like image 149
javaBean007 Avatar answered Sep 19 '22 19:09

javaBean007