How to override some bootstrap attributes?

0

I took a menu from the internet that uses the bootstrap framework, when it is on a screen larger than 768px the menu color was initially light gray, I changed to dark gray, but when the screen is smaller than 768px, the menu turns gray Of course again, I would need to overwrite the place that makes the menu go back to light gray, but I do not know how to use the @media tag (if that's what I should use). Just put in the css file something like this:

@media (min-width:768px) {
    .navbar navbar-default navbar-fixed-top {
        background-color: gray;
    }

Or is this format wrong?

    
asked by anonymous 30.05.2017 / 18:22

3 answers

1

In this link in Stackoverflow in English you have the list of all media queries used.

The question they asked was which breakpoints of Bootstrap 3 and user list all with comments. Take the code he posted adds your custom css into the half queries you'd like to be affected.

    
30.05.2017 / 18:33
5

Missing "points" in:

.navbar navbar-default navbar-fixed-top

It should look like this:

.navbar .navbar-default .navbar-fixed-top

I'm not sure, but it seems like a } is missing too, it should look like this:

@media (min-width:768px) {
    .navbar navbar-default navbar-fixed-top {
        background-color: gray;
    }
}

If it does not work, use !important

@media (min-width:768px) {
    .navbar .navbar-default .navbar-fixed-top {
        background-color: gray !important;
    }
}

Read who has priority, it is very important to understand this:

30.05.2017 / 18:29
2

Note that if you want to add the style when the width is less than 768px, you should use max-width:768px . Here explains in detail the mean queries.

Another interesting fact would be to use !important to make sure you add the style.

Here is an example that adds background-color:gray when width is less than or equal to 600px:

.navbar {
  background-color: black;
  height: 20px;
  width: 100%;
  color: white;
  text-align: center;
}

@media (max-width:600px) {
  .navbar {
    background-color: gray !important;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="navbar">
  navbar
</div>
    
30.05.2017 / 18:33