- div and span
- classes vs. ids
- styling navigation links
- introduction to tables
- table elements
div and span
div and span are tagsets which allow you to define your own blocks of code for styling. Both of them require either a class or id to be assigned.
- Use div to define a block of code that can be styled and positioned using css. The div tag is a block-element tag
- Use span to define a block of code for styling. The span tag is an in-line element, and thus is not appropriate for positioning.
<div class="contentblock">Some content <span class="tabledata">other content</span> last content.</div>
class or id?
- Configure a class:
- If the style may apply to more than one element on a page
- Use the . (dot) notation in the style sheet.
- Use the class attribute in the HTML.
- Configure an id:
- If the style is specific to only one element on a page
- Use the # notation in the style sheet.
- Use the id attribute in the HTML.
styling navigation links
- A navigation system is really just a series of list items
- It makes semantic sense to structure navigation bars as lists and style them with CSS
- A sample navigation system
- We can change the list from vertical to horizontal orientation using the
- We also need to apply
float: left;to our various elements and remove extra padding and margins
- As an example, walk through the steps required to recreate a navigation bar described by Roger Johansson in his excellent tutorial.
Your instructor will walk you through the creation of a list-based navigation system for the WidgetWerks site.
introduction to tables
- originally intended for displaying tabular data - information in rows and columns
- was the primary way to do page layout prior to CSS
- markup behind tables is a bit tricky and not entirely intuitive:
- constructed in rows, but columns are implied by number of cells in each row
- a 3x3 table consists of 3 rows, but we must be sure to include 3 separate cells within each row for table to display as intended
- tables can be nested within tables allowing for complex and dynamic page layouts
- three elements required to make a table:
<table></table>- signifies that you are creating a table
<tr></tr>- delimits a table row
<td></td>- delimits the data in a table cell
- a sample table:
<tr><td>top left</td><td>top right</td></tr>
<tr><td>bottom left</td><td>bottom right</td></tr>
- Also: See pages 357-359 for information on table headers and captions
- old school table attributes (see page 357):
border- draws lines around your table:
width- specifies width of table in percentage or pixels:
<table border="1" width="300">
cellpadding- adds space (in pixels) around objects in table cells:
<table border="1" width="300" cellpadding="10">
cellspacing- adds space to borders between cells:
<table border="1" width="300" cellpadding ="10" cellspacing="10">
- as with many attributes, there are default values - if you want them set to "zero" you must specify
<td>attributes (see page 358):
width- width of cell in pixels
align- alignment of elements in cell (
valign- vertical alignment of elements in cell (
colspan- cell spans 2 or more columns
rowspan- cell spans 2 or more rows
bgcolor- often specified in hexidecimal code (e.g.
<tr>tag can also accept
bgcolorto apply the same values to an entire table row (see page 358):
- See page 364 in your textbook for corresponding CSS properties
Use the notes above to help recreate the tables on this page.
If you get through the two tables quickly enough, experiment adding styles (see page 380) to the table using your textbook/the web as a reference. Here are some ideas:
- Use your own devices and colour choices to create embedded styles to:
- Change the background colour of the tables.
- Change the background colour of one of the rows of the tables.
- Change the background colour for one or more of the table cells in the tables.
- Add an overall width of 600px to the table.
- Add more text to one of your cells. What happens to the table? The other cells? Change the vertical alignment of text so that it's different for every cell in a row. Do you see a change? What if you add more text?
Reformat the WidgetWerks pages using tables to format appropriate content.
- Replace the ordered and unordered lists on partners.html with a table (2 columns, 1 header row and 5 regular rows).
- Follow the hands on practice (8.3) steps starting on page 380 of your textbook (PDF file of selected pages; bring your textbook to class!) to style the table (ignore step 4 re: caption). Use the following colours in place of those suggested in the book:
- Replace the definition lists on stuff.html with tables.
- Advanced: Review sections 8.6 and 8.7 (pgs. 366-368) and apply sections to your product listing.
- Add a link to the stylesheet so that the tables display the same as on the partners page.
- Complete the Web Research exercises (numbers 1 and 2) at the end of Chapter 3 in Web Development & Design Foundations that starts on page 122.
- Upload your exercises to your account and email your instructor with the proper URL. HINT: it might look something like this:
Exercise is due before the start of the week five class. Your instructor will not hunt you down to hand this in - no email sent to your instructor = zero marks.