PDA

View Full Version : Why not using pseudo classes?



iulian
9 Nov 2013, 8:42 AM
Hi,

Any reason for not using pseudo classes? I understand the reason for having the class also, but why not having also the pseudo class in place? For example, see the below focus class for the field.



.#{$prefix}form-focus {
border-color: $form-field-focus-border-color;
}


But I would also add the :focus.


.#{$prefix}form-focus,
.#{$prefix}form-text:focus {
border-color: $form-field-focus-border-color;
}



I have a custom component with a input inside and I use x-form-text class on it but I don't want to have listeners to add/remove the x-form-focus class.

What do you think? Anything against using it this way?

Thanks,
Iulian

slemmon
11 Nov 2013, 11:29 PM
Pseudo selectors may or may not work in all browsers you might be targeting with your app. Browser adoption is the only reason I've seen for not using them.

While not authoritative perhaps here is the list of selectors and their support in IE that I was able to find:
http://www.impressivewebs.com/browser-support-css3-selectors/

If your app will only be used on a browser supporting a given selector then I see no reason you couldn't use it. But, if you need it to work on legacy browsers your selector choice narrows.