Is this good practice?
No, not really. That's sacrificing valuable pseudo-elements that could be used for generated content or other clever layout tricks (every element can only have one ::before
pseudo-element at a time), to do something that can be done conventionally with margins on the elements themselves.
The typical practice for spacing paragraphs is to specify vertical margins on each paragraph and allow margin collapsing to do the rest:
p {
margin: 20px 0;
}
... because this is what margin collapsing was designed for: so authors can say, "There should be 20px of space between paragraphs", without them having to calculate how much margin each paragraph should have on either end. In other words, this is how CSS implements the concept of paragraph spacing as seen in word processors.
If you don't want this behavior, you need only specify either a top or bottom margin, and change the value of that top or bottom margin wherever it needs to differ. For example:
p {
margin: 20px 0 0 0; /* Equivalent to margin: 0; margin-top: 20px; */
}
h1 + p {
margin-top: 10px;
}
Using pseudo-elements for this is unnecessary.
On most places I have read that margins and padding should be used exclusively, but I found that I depend too much on id selectors when using them.
On the same topic, if I were to use them, should I use margin or paddings? On some places I have read that margins are prefered, yet on others that padding should be used for typography.
This is too broad to answer concisely, but I will say that margins and padding can be used together in some situations as they serve different purposes in layout.
That being said, whenever you find yourself wondering if you should use one or the other, as a starting point consider what they were designed for: margins create space outside an element (that can interact with other margins in various ways); padding creates space inside an element to give its children breathing room away from its content edge. Again, there are a number of situations where it's not so simple, but unfortunately it would be too broad to cover in one answer.
It's not clear to me what that hearsay refers to by "typography".