Lab 13 Tables
Goal
- Build and style a web table
- Learn a new pseudo-class selector
Learn
<table>
<thead>
<tr>
<th>Header Content 1</th>
<th>Header Content 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Body Content 1</td>
<td>Body Content 2</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Footer Content 1</td>
<td>Footer Content 2</td>
</tr>
</tfoot>
</table>
The HTML <table>
element represents tabular data — that is, information presented in a two-dimensional table comprised of rows and columns of cells containing data.
Tables should not be used for formatting a website's layout. They should only be used for displaying data. The exception to this is email code. Emails are built using table tags.
<thead>
- defines a set of rows defining the head of the columns for the table.
<tbody>
- encapsulates a set of table rows, <tr>
elements, indicating that they comprise the body of the table.
<tfoot>
- defines a set of rows summarizing the columns for the table.
<tr>
- defines a row of cells in a table. The row's cells can then be established using a mix of <td>
(data cell) and <th>
(header cell) elements.
<th>
- defines an individual cell as header of a group of table cells
<td>
- defines an individual cell of a table that contains data
<td colspan="8">Span 8 Columns</td>
While there are some attributes you can use to style tables but they are outdated and deprecated. Tables should be styled with CSS.
The only table specific attribute we will be using is colspan. This attribute is used to make a cell span multiple columns.
tr:first-child{
color:red;
}
tr:last-child{
color:blue;
}
tr:nth-child(2){
color:green;
}
tr:nth-child(even){
color:yellow;
}
tr:nth-child(odd){
color:pink;
}
The :nth-child() CSS pseudo-class matches elements based on their position among a group of siblings.
:first-child
- This selector will select the first element in a group of siblings
:last-child
- This selector will select the last element in a group of siblings
:nth-child(n)
- This selector will select the number element specified by the integer used for n in a group of siblings. So for example tr:nth-child(3) would select the third row.
:nth-child(even)
- This selector will select the even elements in a group of siblings
:nth-child(odd)
- This selector will select the odd elements in a group of siblings.
Practice
Experiment Try changing the first <tr>
font to red, the last <tr>
font to blue, and the third <tr>
font to green.
HTML
CSS
Preview
Open GitHub Desktop (you may need to download the program again if the computers get wiped.)
Couple of things to check in GitHub Desktop.
- Check to see if it says Pull Origin. If it does, click Pull Origin. Why? A pull occurs if you or a collaborator made a change to the repository and pushed the changes. ALWAYS MAKE SURE TO PULL BEFORE CODING!
- If the computers were wiped you made need to reclone your repository to the computer.
With your cs-318 repository selected, Click open in Visual Studio code.
Create a new folder called lab12
Create a new file called index.html in the lab12 folder
Setup your HTML files
Create your stylesheet
Link your stylesheet to the HTML
Change Document in the <title>
element to "Lord of the Rings Characters"
HTML
Add a <table>
element. Every element from here on down will be in the table.
Add a <thead>
In the <thead>
add each bullet point as a <th>
- Lord of the Rings Characters add this attribute to only this th: colspan="9"
- empty
<th>
- Character
- Aliases
- Race
- Appearance
- Fellowship Member
- Alignment
- Adventures
- Ring Bearer
Then add a <tr>
around the first <th>
and a second <tr>
around the rest of the <th>
in the <thead>
Add a <tbody>
In the <tbody>
add the following 13 times:
<tr>
<td>
- This is the image<th>
- Black bullet point<td>
- 1<td>
- 2<td>
- 3<td>
- 4<td>
- 5<td>
- 6<td>
- 7
Content for the 13 <tr>
in the <tbody>
- Smeagol
- Gollum
- Stoor Hobbit
- A small slimy creature, emaciated and gaunt, but possessing a vicious, wiry strength.
- No
- Neutral Evil
- The Fellowship of the Ring, The Two Towers, and The Return of the King, The Hobbit
- Yes
- Frodo Baggins
- Mr. Underhill
- Hobbit
- Half the height of humans, feet are covered with curly hair, and stout, with slightly pointed ears.
- Yes
- True Neutral
- The Fellowship of the Ring, The Two Towers, and The Return of the King
- Yes
- Samwise Gamgee
- Samwise the Brave
- Hobbit
- Half the height of humans, feet are covered with curly hair, and stout, with slightly pointed ears.
- Yes
- Lawful good
- The Fellowship of the Ring, The Two Towers, and The Return of the King
- Yes
- Gandalf
- Mithrandir, Tharkun, Olorin, Incanus, Gandalf the Grey, The Grey Pilgrim, The Grey Wanderer, Gandalf the White, The White Rider, Stormcrow
- Maia
- Less tall than the others, and in looks more aged, grey-haired and grey-clad, and leaning on a staff.
- Yes
- Chaotic Neutral
- The Fellowship of the Ring, The Two Towers, and The Return of the King, The Hobbit
- No
- Aragorn
- Strider, Elfstone, Thorongil, Estel, Wingfoot
- Men
- Lean, dark and tall, with shaggy dark hair "flecked with grey", grey eyes, and a stern pale face.
- Yes
- Lawful Good
- The Fellowship of the Ring, The Two Towers, and The Return of the King
- No
- Legolas
- Greenleaf
- Sindar Elf
- Lithe and slender, with bright, keen eyes and ears, and is fair of face.
- Yes
- Neutral Good
- The Fellowship of the Ring, The Two Towers, and The Return of the King
- No
- Gimli
- Elf Friend, Lockbearer, Lord of the Glittering Caves
- Dwarf
- Shorter and stockier than Elves and Men.
- Yes
- Chaotic Good
- The Fellowship of the Ring, The Two Towers, and The Return of the King
- No
- Meriadoc Brandybuck
- Merry, Kalimac Brandagamba, Meriadoc the Magnificent, Master of Buckland, Holdwine of the Mark
- Hobbit
- Half the height of humans, feet are covered with curly hair, and stout, with slightly pointed ears.
- Yes
- Chaotic Good
- The Fellowship of the Ring, The Two Towers, and The Return of the King
- No
- Peregrin Took
- Pippin, Pip, "Ernil i Pheriannath" Thain Peregrin I, Razanur
- Hobbit
- Half the height of humans, feet are covered with curly hair, and stout, with slightly pointed ears.
- Yes
- Chaotic Good
- The Fellowship of the Ring, The Two Towers, and The Return of the King
- No
- Boromir
- Captain of the White Tower, High Warden of the White Tower
- Men
- Tall and sturdy (slightly shorter but stockier than Aragorn), fair, dark-haired, and grey-eyed.
- Yes
- Chaotic Good
- The Fellowship of the Ring, The Two Towers, and The Return of the King
- No
- Sauron
- Mairon the Admirable, Tar-Mairon "King Excellent", Gorthaur, Nameless Enemy, Sauron the Deceiver, Zigar, Dark Lord of Mordor, Lord of the Rings, Base Master of Treachery, The Great Deceiver, the Dark Lord, the Dark Power, Lord of Barad-dar, the Red Eye, the Ring-maker and the Sorcerer, Lord of Werewolves, Annatar, Aulendil, Artano, Necromancer
- Maiar
- Many forms
- No
- Lawful Evil
- The Fellowship of the Ring, The Two Towers, and The Return of the King, The Hobbit
- Yes
- Saruman
- CurunÃr, Curumo, Sharkey, Man of Skill, White Messenger, Head of the White Council, Lord of Isengard
- Maia
- Long face and a high forehead, deep darkling eyes, hair and beard were white, but strands of black still showed around his lips and ears.
- No
- Neutral Evil
- The Fellowship of the Ring, The Two Towers, and The Return of the King
- No
- Bilbo Baggins
- Bilba Labingi, Burglar, Thief
- Hobbit
- Half the height of humans, feet are covered with curly hair, and stout, with slightly pointed ears.
- No
- Chaotic Good
- The Fellowship of the Ring, The Two Towers, and The Return of the King, The Hobbit
- Yes
CSS
body
padding 5rem
background color darkolivegreen
font family Georgia, 'Times New Roman', Times, serif
th
background color darkgreen
font color white
tr:nth-child(even)
background color #ffffe2
tr:nth-child(odd)
background color #e0e0cb
td, th
padding .5rem
thead>tr:first-child>th
Hint: This selector will select the th in first tr in the thead.
font size 2rem
font color goldenrod
.
Notice the space in between all of the table cells. This is cause by the default setting for the property border-spacing.
table
border-spacing:0;
But now the character <th>
are hard to differentiate from the rest of the ths.
tbody th
background color #023802
tbody th:hover
background color #022502
td, th
vertical-align top
td
border 1px solid #023502
tbody tr:hover
background color #D8D8B6
Final Steps
Validate your HTML.
- Navigate to W3C Validator
- Select the validate by file upload tab at the top of the page
Lint your CSS at Jigsaw.w3.org
Now look at GitHub Desktop. You should see all of your files listed out in the left column.
Now you are going to commit your changes.
With all of the files checked. Fill out the Summary field in the bottom left and then click Commit to main.
Committing is staging the files, so they can be pushed to the repository hosted at GitHub.
Now you want to push your changes to the Repository. Now if you access the repository from another computer Lab12 will be there. After you push in the top right of the nav it should say "Fetch Origin" instead of "Push Origin"
Your are Done with Lab12