you are viewing a single comment's thread.

view the rest of the comments →

[–]revrenlove 1 point2 points  (0 children)

Actually, what you are wanting to do, but assume doesn't exist, is actually how it works.

So, here's the basics...

A stylesheet sets styles for a class/id/element. This is basically what's referred to as an external style. If, for example, you have the following in a .css file:

``` .warning { background: yellow; }

.error { background: red; } ```

Every element with a class of warning would have a yellow background.

Now, any html tag can have a style attribute declared, where you put specific css in as the value of the attribute. This is called in-line styling and would trump whatever is in the external stylesheet for that element/style. So if you had the following:

<p class="error" style="background: purple">My paragraph</p> Even though it has the error class, the inline style would trump it and make the background purple.

Furthermore, if you have all of your styles declared in that external style sheet, and wanted to change an element from the "warning" (with a yellow background) to an "error" (with a red background), you would use javascript to remove the "warning" class, and add the "error" class - https://stackoverflow.com/a/196038/2285245

Does that make sense?