In this activity, we'll look at selectors, which allow you more control over what CSS rules are applied to.
tables.html
<table> <thead> <tr> <th>Name</th> <th>Surname</th> <th>Nationality</th> <th>Age</th> <th>Position</th> </tr> </thead> <tbody> <tr> <td>David</td> <td>Ospina Ramírez</td> <td>Colombia</td> <td>33</td> <td>Portero</td> </tr> <tr> <td>Carlos</td> <td>Eccehomo Cuesta Figueroa</td> <td>Colombia</td> <td>22</td> <td>Defensa</td> </tr> <tr> <td>Juan Guillermo</td> <td>Cuadrado Bello</td> <td>Colombia</td> <td>33</td> <td>Centrocampista</td> </tr> <tr> <td>Radamel Falcao</td> <td>García Zárate</td> <td>Colombia</td> <td>35</td> <td>Delantero</td> </tr> </tbody> </table>
style.css
td, th { border-width: 1px; border-style: solid; } td { padding-left: 10px; padding-right: 10px; padding-top: 10px; padding-bottom: 10px; } table { border-collapse: collapse; }
id
which identifies one single element in the page. It must be unique.id
. Let's call it 'carlos'.<tr id="carlos"> <td>Carlos</td>
#
.#carlos { font-style: italic; }
<tr>
and all elements inside it are italicised.id
because that must be unique.class
to every element we want to change. Let's call it 'age'.<table> <thead> <tr> <th>Name</th> <th>Surname</th> <th>Nationality</th> <th class="age">Age</th> <th>Position</th> </tr> </thead> <tbody> <tr> <td>David</td> <td>Ospina Ramírez</td> <td>Colombia</td> <td class="age">33</td> <td>Portero</td> </tr> <tr id="carlos"> <td>Carlos</td> <td>Eccehomo Cuesta Figueroa</td> <td>Colombia</td> <td class="age">22</td> <td>Defensa</td> </tr> <tr> <td>Juan Guillermo</td> <td>Cuadrado Bello</td> <td>Colombia</td> <td class="age">33</td> <td>Centrocampista</td> </tr> <tr> <td>Radamel Falcao</td> <td>García Zárate</td> <td>Colombia</td> <td class="age">35</td> <td>Delantero</td> </tr> </tbody> </table>
.age { background-color: yellow; }
background-color
which sets the background color. This can be applied to any element, including <body>
which will change the page's background.#carlos .age { font-weight: 900; }
td.age { font-size: 150%; }
td
.#carlos .age
with a space between the options says to select the elements with class age inside the element with id carlos. The second td.age
has no space, which says to select elements that are both data cells and class age.