How can I avoid repeating the css and not using !important?

Non

Ok here is the thing, I have a Bootstrap navbar which I'm trying to give some style, lets say this is the portion of code you must focus on

<div class="collapse navbar-collapse">
   <ul class="nav navbar-nav">
     <li class="active"><a class="hover-nieve" href="#/lines">Sports <span class="sr-only">(current)</span></a></li>
     <li><a class="hover-nieve" href="javascript:void(0);">Poker</a></li>
     <li><a class="hover-nieve" href="javascript:void(0);">Casino</a></li>
     <li><a class="hover-nieve" href="javascript:void(0);">Horses</a></li>
     <li><a class="hover-nieve" href="javascript:void(0);">Info</a></li>
   </ul>
</div>

if I do this

  .hover-nieve {
    background: get-color(nieve);
    color: get-color(night);
    transition: all .4s ease;

    &:hover,
    &:focus {
      background: get-color(nieve);
      box-shadow: inset 0 -4px 0 0 lighten(get-color(rose), 5%);
      color: get-color(rose);
      margin: 0;
    }
  }

the background and color part doesn't work, I have to put !important in both cases, the issue I have is that once you do focus on any of those links, the .active is called, so I had to do this

  //when .active
  .active .hover-nieve {
    background: get-color(nieve);
    color: get-color(night);
    transition: all .4s ease;

    &:hover,
    &:focus {
      background: get-color(nieve);
      box-shadow: inset 0 -4px 0 0 lighten(get-color(rose), 5%);
      color: get-color(rose);
      margin: 0;
    }
  }

  // normal behavior
  .hover-nieve {
    background: get-color(nieve);
    color: get-color(night);
    transition: all .4s ease;

    &:hover,
    &:focus {
      background: get-color(nieve);
      box-shadow: inset 0 -4px 0 0 lighten(get-color(rose), 5%);
      color: get-color(rose);
      margin: 0;
    }
  }

and as you see guys, that code is exactly the same code but with the difference of the .active how can I compile that code into one code only for that part, and with out using !important

Josh Burgess

Add greater specificity to the .hover-nieve selector. e.g. body .hover-nieve { ... /* Rules here */ } and your need for !important should no longer be necessary.

Example:

body .hover-nieve {
  background: get-color(nieve);
  color: get-color(night);
  transition: all .4s ease;

  &:hover,
  &:focus {
    background: get-color(nieve);
    box-shadow: inset 0 -4px 0 0 lighten(get-color(rose), 5%);
    color: get-color(rose);
    margin: 0;
  }
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How can I avoid using 'at' in radial-gradient?

分類Dev

Can I avoid using a kubernetes volume

分類Dev

How can I avoid "environment hell" in postman?

分類Dev

How can I avoid losing precision with ftFmtBcd?

分類Dev

How can I avoid a circular reference situation

分類Dev

Django conditional queries: How can I avoid this?

分類Dev

How can I avoid duplicate templates in Meteor?

分類Dev

How i can avoid the distinct() of watchdog?

分類Dev

How can I avoid problems with CPU power?

分類Dev

How to avoid repeating blocks of XAML in a menu

分類Dev

How to avoid repeating the following replace code?

分類Dev

How can I seamlessly grow/shrink elements on hover using CSS?

分類Dev

Why does C# compiler create private DisplayClass when using LINQ method Any() and how can I avoid it?

分類Dev

How can I avoid nested Navigation Bars in SwiftUI?

分類Dev

How can I avoid running some tests in parallel?

分類Dev

How can I avoid Phusion Passenger running as root?

分類Dev

How can i avoid Jquery translate `?` to `%3F`

分類Dev

How can I avoid overwriting dynamodb from two lambdas?

分類Dev

EXC_BAD_ACCESS - How can I avoid it?

分類Dev

How can i avoid or pass over a directory that is access denied?

分類Dev

How can I avoid a black background when fading in an overlay with ffmpeg?

分類Dev

How to avoid repeating sed commands when adding sites to Varnish?

分類Dev

How do I avoid using a million view controllers for tableview list?

分類Dev

How would I avoid using a goto statement here?

分類Dev

How do I avoid duplication of code using AASM?

分類Dev

How can I abstract this repeating pattern in ASP.NET MVC 5?

分類Dev

How can I loop into two different DIVS without repeating in wordpress custom post

分類Dev

Can I avoid mutating in this scenario?

分類Dev

How can i execute a css3 transition when the document loads using javascript?

分類Dev

How can I restructure HTML elements that are side by side and stacked using only css and html?

Related 関連記事

  1. 1

    How can I avoid using 'at' in radial-gradient?

  2. 2

    Can I avoid using a kubernetes volume

  3. 3

    How can I avoid "environment hell" in postman?

  4. 4

    How can I avoid losing precision with ftFmtBcd?

  5. 5

    How can I avoid a circular reference situation

  6. 6

    Django conditional queries: How can I avoid this?

  7. 7

    How can I avoid duplicate templates in Meteor?

  8. 8

    How i can avoid the distinct() of watchdog?

  9. 9

    How can I avoid problems with CPU power?

  10. 10

    How to avoid repeating blocks of XAML in a menu

  11. 11

    How to avoid repeating the following replace code?

  12. 12

    How can I seamlessly grow/shrink elements on hover using CSS?

  13. 13

    Why does C# compiler create private DisplayClass when using LINQ method Any() and how can I avoid it?

  14. 14

    How can I avoid nested Navigation Bars in SwiftUI?

  15. 15

    How can I avoid running some tests in parallel?

  16. 16

    How can I avoid Phusion Passenger running as root?

  17. 17

    How can i avoid Jquery translate `?` to `%3F`

  18. 18

    How can I avoid overwriting dynamodb from two lambdas?

  19. 19

    EXC_BAD_ACCESS - How can I avoid it?

  20. 20

    How can i avoid or pass over a directory that is access denied?

  21. 21

    How can I avoid a black background when fading in an overlay with ffmpeg?

  22. 22

    How to avoid repeating sed commands when adding sites to Varnish?

  23. 23

    How do I avoid using a million view controllers for tableview list?

  24. 24

    How would I avoid using a goto statement here?

  25. 25

    How do I avoid duplication of code using AASM?

  26. 26

    How can I abstract this repeating pattern in ASP.NET MVC 5?

  27. 27

    How can I loop into two different DIVS without repeating in wordpress custom post

  28. 28

    Can I avoid mutating in this scenario?

  29. 29

    How can i execute a css3 transition when the document loads using javascript?

  30. 30

    How can I restructure HTML elements that are side by side and stacked using only css and html?

ホットタグ

アーカイブ