CSS: Is it important to specify the exact path for a specific element for speed / accuracy?

When defining CSS for a particular element, indicating the exact path matters when we talk about speed / accuracy / processing of a web page?

eg. if I have text inputs ONLY in the third column of my table, what is better for speed, accuracy, processing and other parameters?

OPTION 1:

table input[type="text"] { background:yellow; } 

OPTION 2:

 table td:nth-child(3) input[type="text"] { background:yellow; } 
+5
source share
1 answer

No, adding extra selectors just gives the browser more elements to check and therefore more work.

If the inputs will appear only in a certain place, and you can guarantee that they will never appear anywhere else on the given page, then no matter how accurate your selector outside the input[type="text"] is, since he will always aim at the same set of elements anyway. Any additional checks you add become redundant.

But the real question is whether performance is important here. If you do not have tens of thousands of such items, most likely the answer will be no. Be as specific as you feel comfortable. If you need contextual selectors to make sure you don't accidentally target the wrong elements, there is no harm in inserting them.

+7
source

Source: https://habr.com/ru/post/1202675/


All Articles