Web Programming Studio Notes

Week 1 - Day 3

3.1: Tables

Creating a table

A Table is a HTML structure created within the <table> element. They consist of primarily:

  • The <tr> element creates a table row, which contains all the row's cells.

  • The <th> element creates a table cell containing table header information about the data. Usually, the browser displays table headers centered with a bold font.

  • The <td> element creates a table cell containing table data.

A table caption defines a short descriptive text for a table and is created with the <caption> element. The caption element must immediately follow the opening <table> tag. A web browser typically renders the table caption centered above the table.

To add borders to your table you can do that using CSS

<style>
    table, th, td 
    {
        border: 2px solid gray;
    }
</style>

Accessible Tables

People that use screen readers to hear table content benefit from the proper use of elements for table headings. Complex or long tables may use the scope attribute to improve accessibility. The scope attribute is commonly assigned "col" or "row" to indicate if the table header applies to a column or row of data. Ex:

Spanning multiple columns and rows

You can add the attribute colspan="" or rowspan="" just after your <td>s in order to make the cell span multiple rows or columns NOTE: DO NOT APPLY THESE ATTRIBUTES TO THE <tr> TAGS

Header, body, and footer

Three optional table tags specify each part of a table:

  • The <thead> element specifies the table header.

  • The <tbody> element specifies the table body.

  • The <tfoot> element specifies the table footer.

The <thead>, <tbody>, and <tfoot> elements do not affect the layout of the table, but browsers may use the elements to enable the table body to scroll independently of the header and footer or to print the header and footer on each page of a multi-page table printout.

Exploring further:

3.2: Images

The <img> is a void element that requires one attribute to function and two in order to comply with the standards

  • src="" which specifies what image to display

  • alt="" which states the alt text for screen readers and accessability or in the case of the image failing to load

The width="" and height="" attribute tells the browser what size to display the image as, if only one parameter is set the image aspect ratio is maintained

Favicon

A favicon is the icon that appears in the task bar, you can change it by using a <link> in the head of your page

<link rel="icon" href="image link">

Exploring further:

3.4: Special Characters

Non Breaking Characters

Non breaking characters allow for the browser to display a gap such as a space or a hyphen without having the word split such as when writing 2‑2.5". It is highly suggested to add a non‑breaking space to things like blank cells in tables in order to guarantee that the browser will behave correctly and render the cell.

Image with character entities

Exploring further:

3.5: HTML Containers

Containers and parent containers

A container is any element in a web document body that has opening and closing tags. Web developers typically create many containers as a convenience to assist in organizing and formatting content. Ex: Containers can be formatted by applying styles to adjust margins, padding, horizontal and vertical alignment, and other visual presentation attributes.
A parent container is the container in which another element resides.

Image showing common HTML containers

Block elements

HTML elements can be categorized as either block or inline. A block element (sometimes called a block-level element) fills the width of the element's parent container and can contain other block elements, inline elements, and text. Block elements include <h1>, <table>, and <p>.
Some block elements cannot be contained within certain other block elements when the semantics are unclear. Ex: The <p> element cannot contain another <p> element.
A block element is typically displayed starting and ending on new lines. Ex: The <ol> element is a block element, and each ordered list starts on a new line separate from previous and following blocks.
The <div> element is a generic element for creating block containers. Unlike other block elements, such as <p> and <table>, <div> is the only block element with no semantic meaning.

Inline elements

An inline element fills the minimum space possible in the element's parent container and can only contain text or other inline elements. Ex: The <a> element is an inline element that creates a hyperlink container as big as the link's internal content; a hyperlink does not fill the width or height of the link's parent paragraph.
The <span> element is a generic inline element. Unlike other inline elements, such as <a> and <em>, the <span> element has no semantic meaning.
Since <div> and <span> do not have semantic meaning, <div> and <span> are used primarily for presentation and interaction purposes. Good practice is to use elements like <address> and <article> that convey semantic meaning when creating containers, and use <div> and <span> only when no other elements are appropriate.