Currently, I am in the process of creating a sophisticated calculator using html5/css3/js. An interesting challenge arose when attempting to style the operator
elements uniquely to differentiate them from the other keys (0-9).
In my CSS file, I tried styling with .keys .operator
, but unfortunately, the background property did not apply as expected.
After adjusting it to .keys span.operator
, the styling worked. However, this left me puzzled.
The question at hand:
Why is it necessary to be so specific for the CSS to recognize the background property? Why can't I simply use the .operator
class on its own?
I believed that by using .keys .operator
, I would target all elements with a class of .operator
within any element with a class of .keys
.
Despite the logic behind it, it didn't yield the expected results.
If following the strict CSS hierarchy, one might think that writing div.keys span.operator
would be required, but surprisingly, it isn't in this tutorial.
If anyone could provide an explanation, I would greatly appreciate it.
Below is the code I am currently working on: