thoughtbot / bourbon

A Lightweight Sass Tool Set
https://www.bourbon.io/
MIT License
9.1k stars 879 forks source link

How to get important in position #562

Closed shivapoudel closed 9 years ago

shivapoudel commented 9 years ago

I have done this:

.axis-search-tooltip {
    @include position(absolute, 85% !important null null null);
}

But I got

.axis-search-tooltip {
  position: absolute;
  top: 85%; // `!important` is missing guys :)
}

What I need strictly was

.axis-search-tooltip {
  position: absolute;
  top: 85% !important;
}
tysongach commented 9 years ago

We don’t accept !important statements within the mixins and generally frown upon the use of them. If you really need to use one, just break out your CSS.

colinwren commented 8 years ago

I think this issue (or a related issue) is worth reopening. While it is true that using !important incorrectly (as it most often is) can make CSS codebases a pain to work with, !important can be quite useful in an OOCSS context.

An app I am currently working on utilizes utility classes such as .u-displayNone which are meant to be trump classes (never overridden), these classes use !important to ensure their styles are always applied. You could achieve this same effect in a specificity flat CSS codebase (all css rules are same level of specificity) by putting your trump classes at the end of the cascade, but unfortunately it is very difficult to have a specificity flat CSS codebase if you are using jQuery plugins or have complicated hover states.

I would love to be able to use bourbon's powerful mixins in my utility classes, but I can't until they support !important.

tysongach commented 8 years ago

@colinwren I see your point, but it’s a slippery slope. If we add this to position, should it also be added to a bunch of other features here in Bourbon? Where would we draw the line for mixins that have the ability to output !important flags onto specific properties, and ones that don’t?

I think we all aim to not use them, and therefore the amount of times they are required should be low, or we’re trying to make that count low. And with that, I think of it as almost a feature that position doesn’t allow you to declare !important, because it makes it that much more clear that the flag had to be used in the first place.