This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
web_design:horario:selectors [2021/10/11 09:03] mag created |
web_design:horario:selectors [2023/08/16 09:33] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Web Development Lesson 3 - Tablas ====== | ====== Web Development Lesson 3 - Tablas ====== | ||
===== Selectors ===== | ===== Selectors ===== | ||
+ | ==== Objective ==== | ||
+ | In this activity, we'll look at selectors, which allow you more control over what CSS rules are applied to. | ||
+ | |||
==== Setup ==== | ==== Setup ==== | ||
+ | * As usual, we'll build on previous work in this activity using [[https:// | ||
+ | **HTML** | ||
+ | < | ||
+ | < | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | </ | ||
+ | < | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | **CSS** | ||
+ | < | ||
+ | border-width: | ||
+ | border-style: | ||
+ | } | ||
+ | |||
+ | td { | ||
+ | padding-left: | ||
+ | padding-right: | ||
+ | padding-top: | ||
+ | padding-bottom: | ||
+ | } | ||
+ | |||
+ | table { | ||
+ | border-collapse: | ||
+ | }</ | ||
+ | |||
+ | ==== ID ==== | ||
+ | * You may have noticed that using styles in HTML lets you change a single element, while using CSS lets you change all associated elements, but what if you want to change just certain elements? | ||
+ | * To do this we use selectors, which identify the specific elements you want to treat differently. | ||
+ | * The first of these is < | ||
+ | * Let's highlight the data for Carlos in yellow. | ||
+ | * First, we need to specify the row, but giving it an < | ||
+ | < | ||
+ | < | ||
+ | * Now we can apply a rule to this row with CSS using < | ||
+ | < | ||
+ | font-style: italic; | ||
+ | }</ | ||
+ | * Now the < | ||
+ | |||
+ | ==== Class ==== | ||
+ | * Say we want to highlight the age of every player, We can't use < | ||
+ | * Instead, we apply a < | ||
+ | < | ||
+ | < | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <th class=" | ||
+ | < | ||
+ | </tr> | ||
+ | </ | ||
+ | < | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <td class=" | ||
+ | < | ||
+ | </tr> | ||
+ | <tr id=" | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <td class=" | ||
+ | < | ||
+ | </tr> | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <td class=" | ||
+ | < | ||
+ | </tr> | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <td class=" | ||
+ | < | ||
+ | </tr> | ||
+ | </ | ||
+ | </ | ||
+ | * In this example, I've included the header cell because it would look strange without it. | ||
+ | * Now, let's give this a yellow background to make it stand out a bit. | ||
+ | < | ||
+ | background-color: | ||
+ | }</ | ||
+ | * Notice the new style < | ||
+ | |||
+ | ==== Combining Selectors ==== | ||
+ | * Say we want to give the intersecting cell even more impact. We can do so by combining the row and column selectors. | ||
+ | < | ||
+ | font-weight: | ||
+ | } | ||
+ | * We can also limit in other ways, One is to use a combination of elements and classes. | ||
+ | * The following code will only change the non-heading (data) cells with the age class. | ||
+ | < | ||
+ | font-size: 150%; | ||
+ | }</ | ||
+ | * When you run this, you should see the numbers in the age column grow bigger by 50%, but the heading will remain the same because it's not a < | ||
+ | * Notice the difference between the last two examples. The first < | ||
+ | * There are many other ways of specifying and combining selectors, but these are the main ones you'll use often. For more, follow the link on the Summary page. | ||
+ | |||
+ | [[web_design: |