I apologize in advance if this forum is strictly for debugging. My code is passing fine, but I have a couple of questions:
Firstly: Why does it want me to put
h1 .flex{}
when there is only a single flex in the html code? Why not just .flex{} ?
And secondly: This thing. Just. This thing.
span[class~=“sr-only”] {}
What the Frankenstein is this unholy selector. I spent way too much time trying to parse it and what it’s supposed to be targeting/doing, up to and including changing it from “sr-only” to something else in order to make it visible (in the html too, of course). There was also a lot of googling and some drafting on physical paper. I still don’t get it. I may just be dumb. Am I actually supposed to understand that monstrosity at this point in the course?
I think you are right. The tilde in this instance works with attributes that have a space-separated list of values. It will match if the list includes the value in the selector. I think you would generally use this with custom data attributes:
data-info="one two three"
And then you could do:
[data-info~="two"]
And it would match it because “two” is one of the values in the data-info list. Since the class attribute takes a space separated list of values as well you can also use the tilde for classes. But class is kind of special in that it allows you so use the period to select a class from the class list, a very nice shortcut, so you probably wouldn’t use the tilde for classes and it may even seem odd to use it, as is done in step 30.
I can’t comment on why it was done this way in step 30, and technically there is nothing wrong with it. But it’s probably not something you will see too often with regards to class.
And I could be wrong, there may be some difference that I’m not seeing. Never say never
The selector does scope it to a span element but other than that using the class should work the same span.sr-only
I rarely if ever use that attribute selector. I can see it might be handy for web scraping or some other instance where you do not have access to the HTML but have to style it. Other than that, its use cases seem a bit limited.
@lasjorg@bbsmooth Thanks! That’s what I thought, but I’m a beginner, so I was certain I was missing something. It did seem like a clunky solution, because, as you point out, the class selector already exists as a kind of special case. Maybe they’re just trying to get us to think In that case, it worked?
Either way, thanks for your help! I’m gonna conclude that if there is a distinction, it’s not very important and I should probably learn about other things first
Edit: I tried to select both your replies as solutions, but it wouldn’t let me. Sorry, lasjorg, here’s a instead!