Posts: 864
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
I have been working late, and just used the !important remark twice in a row. I remembered this thread, and it just occurred to me a correct usage for this item.
I have a class, which I call 'inviz'. All it does is make an item invisible. It functions like this:
Code:
.inviz {
position: absolute !important;
left: -9999px !important;
}
The reason I specify it this way is the way this class is used: dynamically. In other words, I am using Javascript to place this class (or remove it) from various elements on the page, thereby hiding them or revealing them in real time.
The easiest and best way to create this class is with the !important tag, because it overrides the specificity. Often, you must be careful about overriding specificity, because it is an important element in CSS structure, but in this case, it is exactly what I want. If I place this class on an element, I want it to be the most powerful class on the div, p, or whatever I want to make invisible. I don't want position of relative, for example to take precedence over my absolute, just because it is more specific. Also, I don't want to make a specific rule for each case where 'inviz' might be needed, because that would be too much work. Time is money.
|