- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I’m applying color to different text and I want to know if this is good or bad.
instead of having multiple selectors with commas point to one color which saves a lot of lines of code-
example
p, .content, #idunno{ color:white}
instead I make a class called color1 and add the class anywhere i want a certain color.
i feel this is easier because i can just pull the class off on the html side and its gone.
it also helps me keep my color scheme to a minimum and realize when I am using too much variations of the same color.
I’ve always been taught that creating classes with a color name are a bad idea. Why?
.red {
color:blue;
}
I wouldn’t say it’s “bad” but it certainly creates more work and makes no sense to those viewing your code.
thats not what I was doing.
the class was called color1
I wouldn’t use classes for colors because of the single use of a class is wasteful to me but it wouldn’t hurt your overall sheet via caching or anything as it won’t add that much. Depending on the amount of classes.
You can use multiple classes in an element so if you are doing that it could work and may save time.
For example:
In the long run it could save time but whether it is a best practice, not really but when is a consensus ever really 100% correct. :) BUT you are probably wanting to do this to allow a single variable to be added whenever necessary…this can also be done via PHP.
Chris made an article a couple years back about this…give it a look and see if this helps you with what you are wanting to do. https://css-tricks.com/css-variables-with-php/