The Problem
In my case, I was trying to make the labels of a radio button group appear disabled. Only the buttons themselves would look disabled, but the labels looked the same as when the control was enabled.I don't feel that there is enough distinction between Enabled on the left, and Disabled on the right. |
XPages makes it easy for you to specify a disabled styleClass |
For some reason the "color" is overwritten by OneUI |
The Solution
The way to override is to add “!important” after the attribute you don’t want to be overwritten. In my case, the only attribute that wasn’t behaving was the color. After I added !important, it worked exactly like I wanted. In the right picture above shows what this one change gives you.
.radio-disabled {
font-size:14pt;
font-family:Calibri;
color: #AFAEB5;
}
Here is the After code:
.radio-disabled {
font-size:14pt;
font-family:Calibri;
color: #AFAEB5 !important;
}
The Finished Result
Enabled on the left, disabled on the right. It is easy to distinguish which is which. |
Final Thoughts
Perhaps this is old news to some who read this. Though, in my office, none of the four XPages developers knew about this before. I hope that this helps other XPagers who wrestle with OneUI.I will add that, this should be something that is used sparingly. In my case, only the specific class of “.radio-disabled” is using it. I can see that you could really mess your UI by overusing !important. Here is a related article called “Don’t Use !important” that explains some of the pitfalls.
The reason that color is getting over-ridden in this case, is due to CSS specificity rules. The more specific a CSS selector is, the more weight it has, and it will over-ride less specific CSS. In the example, the OneUI CSS uses 1 class selector + 2 element selectors, whilst yours only uses 1 class selector. Thus, the OneUI CSS has more weight, and overrides your CSS, with color being the only overlapping property. Using "!important" is a brute force method of overriding all CSS to make sure yours is applied. But as you have said, it's better to avoid using that. It would be better to use higher specificity to override the CSS, so in this example, define your CSS with something like ".lotusForm td label.radio-disabled". That has 2 class selectors and 2 element selectors, and will override the OneUI CSS without resorting to the use of !important. More info on css specificity: http://www.smashingmagazine.com/2010/04/07/css-specificity-and-inheritance/
ReplyDeleteBrian, Thanks for your very informative comment. At first, I tried several combinations of defining the classes together and couldn't find the right combination apparently.
DeleteNo problem. Believe me when I say I've been in similar situations myself, and !important was the only way out
DeleteI'm not a fan of using !important but have also come across situations where i have had no choice.
ReplyDeleteI've used it in the past style sheet to override some inline styling i had no control over.