HTML-5-Notes-For-Professional-chapter-8-9(tables and comments)

HTML 5 Notes For Professional – Chapter – 8 – 9 (Tables & Comments)

TABLES

The HTML

element allows web authors to display tabular data (such as text, images, links, other tables,etc.) in a two-dimensional table with rows and columns of cells.

Simple Table

Heading 1/Column 1 Heading 2/Column 2
Row 1 Data Column 1 Row 1 Data Column 2
Row 2 Data Column 1 Row 2 Data Column 2

This will render a

consisting of three total rows (): one row of header cells (, , or ).

colspan = A non-negative integer that specifies the number of columns spanned by the current cell. The default value of this attribute is one (1). A value of zero (0) means that the cell will extend from the current to the last column of the column group

in which the cell is defined.

Column Groups

Sometimes you may want to apply styling to a column or group of columns. Or for semantic purposes, you may want to group columns together. To do this, use

and elements.

The optional

tag allows you to group columns together. elements must be child elements of a
) and two rows of content cells (). elements are tabular headers and elements are tabular data. You can put whatever you want inside a or .
Heading 1/Column 1Heading 2/Column 2
Row 1 Data Column 1Row 1 Data Column 2
Row 2 Data Column 1Row 2 Data Column 2

Spanning columns or rows

Table cells can span multiple columns or rows using the colspan and rowspan attributes. These attributes can be applied to

and elements.
row 1 col 1 row 1 col 2 row 1 col 3
This second row spans all three columns
This cell spans two rows row 3 col 2 row 3 col 3
row 4 col 2 row 4 col 3

Will result in

row 1 col 1 row 1 col 2 row 1 col 3
This second row spans all three columns
This cell spans two rows row 3 col 2 row 3 col 3
row 4 col 2 row 4 col 3

Note that you should not design a table where both rows and columns overlap as this is invalid HTML and the result is handled differently by different web browsers.

rowspan = A non-negative integer that specifies the number of rows spanned by a cell. The default value of this attribute is one (1). A value of zero (0) means that the cell will extend from the current row until the last row of the table (

and must come after any elements and before any table content (e.g., , , , etc.).
...

The optional tag allows you to reference individual columns or a range of columns without applying a logical grouping. elements are optional, but if present, they must be inside a element.

 ...

The following CSS styles can be applied to and elements:

  • border
  • background
  • width
  • visibility
  • display (as in display: none)
    • display: none; will actually remove the columns from the display, causing the table to render as if those cells don’t exist

For more information, see HTML5 Tabular data.

Table with thead, tbody, tfoot, and caption

HTML also provides the tables with the , , , and elements. These additional elements are useful for adding semantic value to your tables and for providing a place for separate CSS styling.

When printing out a table that doesn’t fit onto one (paper) page, most browsers repeat the contents of on every page.

There’s a specific order that must be adhered to, and we should be aware that not every element falls into place as one would expect. The following example demonstrates how our 4 elements should be placed.

Table Title
Header content 1 Header content 2
Body content 1 Body content 2
Footer content 1 Footer content 2

The following example’s results are demonstrated twice–the first table lacks any styles, the second table has a few CSS properties applied: background-color, color, and border*. The styles are provided as a visual guide and is not an essential aspect of the topic at hand.

Html Tables Comments
Table with thead, tbody, tfoot, and caption
ElementStyles Applies
Yellow text on black background.
Bold text on purple background.
Text on blue background.
Text on green background.
Orange borders.
Red borders.

Heading scope

th elements are very commonly used to indicate headings for table rows and columns, like so:

Column Heading 1 Column Heading 2
Row Heading 1
Row Heading 2

This can be improved for accessibility by the use of the scope attribute. The above example would be amended as follows:

Column Heading 1 Column Heading 2
Row Heading 1
Row Heading 1

scope is known as an enumerated attribute, meaning that it can have a value from a specific set of possible values. This set includes:

  • col
  • row
  • colgroup
  • rowgroup

References:

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th#attr-scope
https://www.w3.org/TR/WCAG20-TECHS/H63.html

COMMENTS

Similar to other programming, markup, and markdown languages, comments in HTML provide other developers with development specific information without affecting the user interface. Unlike other languages however, HTML comments can be used to specify HTML elements for Internet Explorer only. This topic explains how to write HTML comments, and their functional applications.

Creating comments

HTML comments can be used to leave notes to yourself or other developers about a specific point in code. They can be initiated with <!– and concluded with –>, like so:

They can be incorporated inline within other content:

This part will be displayed .

They can also span multiple lines to provide more information:

However, they cannot appear within another HTML tag, like this:

>This will not work

This produces invalid HTML as the entire

block would be considered a single start tag h1 with some other invalid information contained within it, followed by a single > closing bracket that does nothing.

For compatibility with tools that try to parse HTML as XML or SGML, the body of your comment should not contain two dashes --.

Commenting out whitespace between inline elements

Inline display elements, usually such as span or a, will include up to one white-space character before and after them in the document. In order to avoid very long lines in the markup (that are hard to read) and unintentional white-space (which affects formatting), the white-space can be commented out.


I hope there will be no extra whitespace after this!

Try it without a comment between the inline elements, and there will be one space between them. Sometimes picking up the space character is desired.

Example code:


I hope there will be no extra whitespace after this!

I hope there will be no extra whitespace after this!

Output:

Image 2019 11 06 At 6.46.20 PM

Pin It on Pinterest