Difference between revisions of "Template:Diagonal split header/doc"

From blackwiki
Jump to navigation Jump to search
imported>Cmglee
(→‎Usage: Add subsections and improve example)
imported>Cmglee
(→‎Usage: Use CSS to pad)
Line 5: Line 5:
 
This template simulates a table header cell split diagonally, a device often used to compactly label headers of rows and columns, as in this example:
 
This template simulates a table header cell split diagonally, a device often used to compactly label headers of rows and columns, as in this example:
 
{| class="wikitable" style="margin:0 auto;text-align:center;"
 
{| class="wikitable" style="margin:0 auto;text-align:center;"
! {{diagonal split header|From |To}} !! Solid !! Liquid !! Gas
+
! {{diagonal split header|<span style{{=}}"padding-right:2em;">From</span>|To&nbsp;}} !! Solid !! Liquid !! Gas
 
|-
 
|-
 
! Solid
 
! Solid
Line 19: Line 19:
 
To use it, create a header cell using <code>!</code> followed by <code><nowiki>{{diagonal split header|NATURE-OF-ROW-HEADERS|NATURE-OF-COLUMN-HEADERS}}</nowiki></code>.
 
To use it, create a header cell using <code>!</code> followed by <code><nowiki>{{diagonal split header|NATURE-OF-ROW-HEADERS|NATURE-OF-COLUMN-HEADERS}}</nowiki></code>.
  
As the effect is achieved by drawing a diagonal line across the cell, the two headers are still part of the same cell and can easily overrun the line. A remedy is to pad the headers with non-breaking spaces (<code>&amp;nbsp;</code>) and/or line breaks (<code>&lt;br /&gt;</code>), as in the example above. The template user is responsible for checking that it does not overrun on common Web browsers.
+
As the effect is achieved by drawing a diagonal line across the cell, the two headers are still part of the same cell and can easily overrun the line. A remedy is to pad the headers with non-breaking spaces (<code>&amp;nbsp;</code>), line breaks {{nobr|(<code>&lt;br /&gt;</code>),}} and/or CSS (escape <code>=</code> signs as <code><nowiki>{{=}}</nowiki></code>), as in the example above. The template user is responsible for checking that it does not overrun on common Web browsers.
  
 
=== Background colour and non-header cells ===
 
=== Background colour and non-header cells ===

Revision as of 18:53, 6 July 2017

Usage

This template simulates a table header cell split diagonally, a device often used to compactly label headers of rows and columns, as in this example:

To 
From
Solid Liquid Gas
Solid Solid-solid transformation Melting Sublimation
Liquid Freezing Boiling/evaporation
Gas Deposition Condensation

To use it, create a header cell using ! followed by {{diagonal split header|NATURE-OF-ROW-HEADERS|NATURE-OF-COLUMN-HEADERS}}.

As the effect is achieved by drawing a diagonal line across the cell, the two headers are still part of the same cell and can easily overrun the line. A remedy is to pad the headers with non-breaking spaces (&nbsp;), line breaks Template:Nobr and/or CSS (escape = signs as {{=}}), as in the example above. The template user is responsible for checking that it does not overrun on common Web browsers.

Background colour and non-header cells

A third parameter can be added to change the background colour from the standard header cell colour. Changing it to white, #fff, or #f8f9fa (the standard non-header background colour) lets the template be applied to non-header cells. Prefix it with | instead of !, as in this Friend or Foe? payoff matrix:

Pair 2
Pair 1
"Friend"
(cooperate)
"Foe"
(defect)
"Friend"
(cooperate)
1
1
2
0
"Foe"
(defect)
0
2
0
0

Spanning columns and rows, and collapsible and sortable tables

The template is compatible with collapsible tables, and cells using colspan or rowspan, in which case place the colspan/rowspan attribute between ! and {{diagonal split header …}}. It is not compatible with sortable tables, as the sort arrows are not drawn, but this problem can be resolved by using a second header row:

n
Township
2025 2026
Nov Dec Jan
Aoraki Mount Cook 8 1 6
Aparima Riverton 3 5 7
Waiau Franz Josef 4 9 2

Template data

Simulate a table header cell split diagonally

Template parameters

ParameterDescriptionTypeStatus
Rows1

header of row headers, shown on the bottom left

Example
''Y-axis''
Stringrequired
Columns2

header of column headers, shown on the top right

Example
{{color|#6cf|X-axis}}
Stringrequired
Background colour3

Optional colour of background, otherwise the standard header background is used

Default
#eaecf0
Example
#f8f9fa
Stringoptional