Sunday, March 24, 2019

Chapter 3: CSS Classes

Chapter 3: CSS Classes


The class selector allows you to style items within the same (X)HTML element differently. Similar to what I mentioned in the introduction of inline styles. Except with classes the style can be overwritten by changing out stylesheets. You can use the same class selector again and again within an (X)HTML file.
To put it more simply, this sentence you are reading is defined in my
CSS file with the following.
p {              
 font-size: small;
color: #333333
}
Pretty simple, but let's say that I wanted to change the word "sentence" to green bold text while leaving the rest of the sentence untouched. I would do the following to my (X)HTML file.
 To put it more simply, this

<p>
 <span>
class="greenboldtext">sentence</span> </p>
you are reading is styled in my CSS file by the following. 

Then in my CSS file, I would add this style selector:

.greenboldtext{
font-size: small;
color: #008080;
font-weight: bold;
}
The final result would look like the following:

To put it more simply, this sentence you are reading is styled in my CSS file by the following.


Please note that a class selector begins with a (.) period. The reason I named it "green bold text" is for example purposes, you can name it whatever you want. Though I do encourage you to use selector names that are descriptive. You can reuse the "green bold text" class as many times as you want.

0 comments: