Why does jQuery UI write CSS like this:
.ui-dialog .ui-dialog-titlebar-close {}
.ui-dialog .ui-dialog-content {}
Since their class names are so descriptive I would think it faster and just as unlikely to have any collisions if they did this:
.ui-dialog-titlebar-close {}
.ui-dialog-content {}
It seems to me they are nesting classes unnecessarily and causing the browser to do more work but I wonder if there’s a good reason for it that I’m not aware of. Does anyone know why they nest the classes as they do?
They do this to be specific.
The element with the class
.ui-dialog-contentalso has several other classes such as.ui-widget-content.To ensure that the rules of
.ui-dialog-contenttrump those of the other classes they add.ui-dialoginfront.This is evident when you inspect the element. The background and border rules of
.ui-widget-contentwill be overridden.