Let's say I have an html element with a class of box:
<p class="box alert">Content here</p>
Recently I learned about a way of targeting elements in CSS, so if I want to select any element with a class of box I could use this:
*[class~=box] {border: 2px solid grey;}
And I'm wondering, isn't it literally the same as just targeting an element by a class name? Or I didn't get it correctly?
.box {border: 2px solid grey;}
If it is the same, in which situations it is appropriate to use the second method rather than the first one?