Why use two different rules for the same selector?

Viewed 57

I was looking around at some examples and noticed that there were two CSS rules with the same selector, doing two different things. Is there a reason they couldn't have been merged?

Example:

.example {
    padding: 0.5em;
    text-align: center;
}

.example {
    background: #ffffff;
}

What's the difference from this?

.example {
    padding: 0.5em;
    text-align: center;
    background: #ffffff;
}
2 Answers

There is no reason at all. It is personal preference to keep them on seperate or keep them together. You can choose to either seperate them or keep them together. No matter which you choose, the end result remains the same.

The reason is a mistake.

If the class has been defined earlier, it should contain all properties here. Duplicating a class is not good practice. It seems to be even a mistake.

Related