I'm re-evaluating the effectiveness of my CSS design choices after reading about SMACSS.
One of the conflicts I've examined is:
<button class="cool-text button"></button>
Semantics aside, the object in question has two classes which do not extend each other in anyway. Now, if the CSS were:
.cool-text {
background-color: black; // want this
color: green; // don't want this
font-size: 16px;
text-shadow: 0 1px 0 yellow;
}
.button {
background-color: white; // don't want this
border: 1px solid;
border-radius: 4px;
color: #eee; // want this
}
Once again, this is not an ideal example. I was wondering, what if I wanted the background-color
from .cool-text
and the color
from .button
. In a programming language, an object can have two classes, and you can specify how to resolve conflicts in method names. I guess similarly, I could specify .cool-text.button
, but I would have to re-write the properties, which seems very bad.
.cool-text.button {
background-color: black;
color: #eee;
}
Are there any workarounds using SCSS?
Also, is it a bad idea to rely on the positions of the classes within the class attribute (in vanilla CSS). Classes that are specified first have higher priority, for instance:
<button class="green-button button"></button>
In this example, .green-button
has higher precedence.
This seems to add CSS specificity to HTML. What if there were lots of classes, you would have to spend time figuring out which ones should go first and that seems very counter-intuitive.
Per Quentin, it's determined by the order within CSS.