Style Change Question

Style Change Question
0

#1

Hello,

Is there a benefit to using a class to change the text color verses the following:

h2 {color: red;}

CatPhotoApp

Thank you


#2

Using a class is nice because then it’s easy add the same class in several places. And easy to change. What if your boss comes to you and says, Yeah, you know, I love that you hand coded in a red color on all 114 of those buttons. But now I’m thinking I want more of a maroon. Let me know when you’re done, there’re a couple more colors I want to try. If you define those as a class in your css, it will take seconds to change.


#3

DIdn’t think about it like that. Thanks for you insight.


#4

Sorry, seeing your question more clearly now.

Yeah, you could code it directly to h2, but what if your boss also wants the same thing for h4? What if he later decides he only wants it on some h2s.

If you are absolutely, 100% sure you will never need to change it, then changing the style of the element is fine. I’m just never 100% of anything.


#5

You can qualify your h2 css.

#thissection h2 {
   color: red;
}

#othersection h2 {
   color: blue;
} 

So depending on the h2’s parent, it will take on a different property.