Sadly you picked two examples that are handled completely differently. The paragraphs example you picked is solved in the more common and powerful way.
If you define a selector a second time, it keeps everything you had before, but anything new is added and anything in conflict it takes the newest declaration (the one farthest down the page, that's where "cascading" comes from in CSS). So...
You will get the color from the first declaration, and background-color from the second. Those two aren't in conflict, no problem. But the margin is defined in both and so the 2nd one wins, you get a margin of zero. And that will affect ALL paragraphs.
If there are paragraphs you want to affect in different ways, that's where classes and ids come in. Pick a default style that you will use most and declare that style for your selector. All the other styles you want to apply will require a class or id. You can read about them at W3Schools.
Anchors can be defined in the same way, however, your example is about the different anchor states, and that requires using pseudo classes. Pretty similar, but it throws an extra kink into the plan especially if you're using links with classes or ids.
Hopefully that will give you a good place to start.