Jump to content

Template:Div col/doc: Difference between revisions

→‎Colwidth: adding variable width example
>Rusty.perrin
(→‎TemplateData: Fix for switch of cols and colwidth between 1st and 2nd parameters, add initial caps aliases, and add small parameter)
 
>Jkudlick
(→‎Colwidth: adding variable width example)
Line 1: Line 1:
{{Documentation subpage}}
{{redirect-distinguish|Template:Colbegin|Template:Col-begin}}
<!-----------------------------------------------------------------------------
<!-----------------------------------------------------------------------------
   PLEASE ADD CATEGORIES WHERE INDICATED AT THE BOTTOM OF THIS PAGE
   PLEASE ADD CATEGORIES WHERE INDICATED AT THE BOTTOM OF THIS PAGE
  ------------------------------------------------------------------------------>
  ------------------------------------------------------------------------------>
{{Documentation subpage}}
{{#ifeq:{{FULLPAGENAME}}|Template:Div col|{{High-use| 269676 }}|{{#ifeq:{{FULLPAGENAME}}|Template:Div col end|{{High-use| 209292 }}}}}}
{{Ombox |type=notice |text=Columns are not supported by some older browsers, most notably Internet Explorer 9 and below and Opera 11.0 and below. See [[Template:Reflist#Browser support for columns|this page]] for more information.}}
{{CSS3 multiple column layout}}
{{CSS3 multiple column layout}}
{{Lua|Module:Check for unknown parameters}}
{{Uses TemplateStyles|Template:Div col/styles.css}}


{{tl|Div col}}, together with {{tl|div col end}}, is used to make a list into columns. It automatically breaks each column into an equal space, meaning, for instance, it isn't necessary to work out the halfway point between two columns. The template also offers options to set a smaller (90%) font-size ({{para|small|yes}}), place vertical lines ("rules") between the columns ({{para|rules}}) and to add other custom styling ({{para|style}}).
The template '''{{tlf|div col}}''' (short for division columns) formats a list into columns that wrap at multiple screen resolutions responsively. It automatically breaks the available screen space into equal parts, meaning, for instance, that it is not necessary to guess how many columns to use and then figure out the dividing point(s), e.g., the halfway point to divide the list into two columns, or the one-third and two-thirds points to divide the list into three columns. To prevent a section of a list being broken, the template {{t|No col break}} can be used.


{{tl|Div col}} can create multiple columns in [[web browser]]s which support one of the following [[CSS]] properties:
==Usage==
* ''column-count'' (for [[Cascading Style Sheets#CSS 3|CSS3]]-compliant browsers; see [http://www.w3.org/TR/css3-multicol/ CSS3 module: Multi-column layout])
===Basic usage===
* ''-moz-column-count'' (for [[Mozilla application framework|Mozilla]]/[[Gecko (layout engine)|Gecko]]-based browsers such as [[Firefox]])
<syntaxhighlight lang="wikitext">
* ''-webkit-column-count'' (for [[WebKit]]-based browsers such as [[Safari (web browser)|Safari]] and [[Google Chrome]])
{{div col}}<!-- default width is 30em -->
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}
</syntaxhighlight>
Produces:
{{div col}}
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}


==Usage==
===Parameters===
; {{para|colwidth}} {{nobold|or first unnamed parameter}}: Specifies the minimum width of the columns and determines automatically the number of columns based on screen width (e.g., more columns will be shown on wider displays). Overrides ''cols''.
There are six parameters for this template:
; {{deprecated code|{{para|cols}} {{nobold|or second unnamed parameter}}}}: {{deprecated code|Specifies the number of columns (default 2). ''(The {{para|cols}} parameter is [[Deprecation|deprecated]], as {{para|colwidth}} is better suited to flexible formatting for a variety of display screen sizes (such as mobile phones vs. widescreen monitors)).''}}
; {{para|colwidth}}
; {{para|rules}}: Adds vertical lines ("rules") between the columns if set to <code>yes</code> or some CSS styling (e.g. <code>1px dashed blue;</code>).
: Specifies the minimum width of the columns so that the number of columns is automatically based on screen width (that is, more columns will be shown on wider displays). If no value is supplied, the template uses a default of 30em. The width can be specified in any [[CSS#Length units|CSS relative or absolute length unit]], for instance, the [[Em (typography)|em]] (about the width of the capital "M" of the displayed typeface), e.g., <code>colwidth=20em</code>.  
; {{para|gap}}: Specifies the space between the content of adjacent columns. The default spacing is 1em.
; {{para|rules|yes}}
; {{para|small}}: Displays column text at 90% of regular size.
: Adds vertical lines ("rules") between the columns if set to <code>yes</code>.
; {{para|style}}: CSS styling to apply to the columns.
; {{para|gap}}
: Specifies the space between the content of adjacent columns, in any valid CSS width unit, e.g., <code>gap=2em</code>. The default spacing (set by browser) is 1em.
; {{para|class}}
: An HTML class, or multiple space-delimited classes, to apply to the columns.
; {{para|style}}
: [[Cascading Style Sheets|CSS styling]] to apply to the columns.
; {{para|small|yes}}
: Sets font size to 90%.
; {{para|content}}
: Content to apply to the columns. This parameter is effectively equivalent to {{tl|columns-list}}, which is a pass-through for this template.
 
===Examples===
====Colwidth====
;Fixed width
<syntaxhighlight lang="wikitext">
{{div col|colwidth=10em}} <!-- column width of 10em -->
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}
</syntaxhighlight>
Produces:
{{div col|colwidth=10em}}
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}
;Variable width
<syntaxhighlight lang="wikitext">
{{div col|colwidth=10vw}} <!-- column width of 10% of the viewable area or container-->
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}
</syntaxhighlight>
Produces:
{{div col|colwidth=10vw}}
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}
 
====Rules====
<syntaxhighlight lang="wikitext">
{{div col|colwidth=10em|rules=yes}} <!-- column width of 10em with rules -->
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}
</syntaxhighlight>
Produces:
{{div col|colwidth=10em|rules=yes}}
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}
 
====Gap====
<syntaxhighlight lang="wikitext">
{{div col|colwidth=10em|rules=yes|gap=2em}} <!-- column width of 10em with rules and a gap of 2em -->
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}
</syntaxhighlight>
Produces:
{{div col|colwidth=10em|rules=yes|gap=2em}}
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}
 
====Small====
<syntaxhighlight lang="wikitext">
{{div col|small=yes}} <!-- Small = yes -->
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}
</syntaxhighlight>
Produces:
{{div col|small=yes}}
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}
 
====Content====
<syntaxhighlight lang="wikitext">
{{div col|colwidth=10em|content= <!-- content parameter doesn't need {{div col end}} -->
* a
* b
* c
* d
* e
* f
* g
* h
}}
</syntaxhighlight>
Produces:
{{div col|colwidth=10em|content=
* a
* b
* c
* d
* e
* f
* g
* h
}}
 
====Multiple parameters====
<syntaxhighlight lang="wikitext">
{{div col|colwidth=10em|rules=yes|gap=2em|small=yes}}
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}
</syntaxhighlight>
Produces:
{{div col|colwidth=10em|rules=yes|gap=2em|small=yes}}
* a
* b
* c
* d
* e
* f
* g
* h
{{div col end}}


==Examples==
====Text characters without list markup====
{|class=wikitable
<syntaxhighlight lang="wikitext">
! width=25% | Usage || Result
{{div col|colwidth=10em}} <!--Text characters without list markup -->
|- valign=top
a
|{{pre|<nowiki>{{div col}}
b
{{lorem|2}}
c
{{div col end}}</nowiki>}}
d
|
e
{{div col}}
f
{{lorem|2}}
g
h
{{div col end}}
{{div col end}}
|- valign=top
</syntaxhighlight>
|{{pre|<nowiki>{{div col|colwidth=200px}}
Produces
{{lorem|2}}
{{div col|colwidth=10em}}
{{div col end}}</nowiki>}}
a
|
b
{{div col|colwidth=200px}}
c
{{lorem|2}}
d
e
f
g
h
{{div col end}}
{{div col end}}
|- valign=top
 
|{{pre|<nowiki>{{div col|cols=3|rules=yes}}
====Lorem ipsum====
{{lorem|2}}
<syntaxhighlight lang="wikitext">
{{div col end}}</nowiki>}}
{{div col}} <!--Lorem ipsum -->
|
{{lorem ipsum}}
{{div col|cols=3|rules=yes}}
{{lorem|2}}
{{div col end}}
{{div col end}}
|- valign=top
</syntaxhighlight>
|{{pre|<nowiki>{{div col|colwidth=150px|small=yes}}
Produces
{{lorem|2}}
{{div col}}
{{div col end}}</nowiki>}}
{{lorem ipsum}}
|
{{div col|colwidth=150px|small=yes}}
{{lorem|2}}
{{div col end}}
{{div col end}}
|}
 
== Limitation ==
=== Sub-lists ===
The underlying CSS system is unable to break sub-lists into columns. Note the uneven formatting below:
 
<syntaxhighlight lang="wikitext">
{{div col|colwidth=10em|rules=yes|gap=2em|style=column-count:3|content=
* a
* b
* c
** c.d
** c.e
** c.f
* g
* h
}}
</syntaxhighlight>
Produces:
{{div col|colwidth=10em|rules=yes|gap=2em|style=column-count:3|content=
* a
* b
* c
** c.d
** c.e
** c.f
* g
* h
}}
 
Turning off the {{code|break-inside: avoid-column;}} rule appears to help.<!-- A full page refersh is needed; just F12-ing doesn't work. -->
 
=== Chrome-based browsers can separate images from captions===
In certain circumstances, Chrome-based browsers can separate images from their captions, placing the caption in the next column. This bug was reported in 2018 as {{phab|T193163}}, and it appears to be a bug in Chromium, [https://issues.chromium.org/issues/40578413 tracked as issue 40578413].
 
==Tracking categories==
* {{category link with count|Pages using div col with unknown parameters}} (for erroneous use of parameter names not documented here)
* {{category link with count|Pages using div col with small parameter}}


==TemplateData==
==TemplateData==
{{TemplateDataHeader}}
{{TemplateData header}}
{{#switch: {{BASEPAGENAME}}
{{#switch: {{BASEPAGENAME}}
|Div col=<templatedata>
|Div col=<templatedata>
{
{
    "description": "Breaks a list into columns. It automatically breaks each column to an equal space, so you do not manually have to find the half way point on two columns. The list is closed with {{div col end}}.",
"description": "Breaks a list into columns. It automatically breaks each column to an equal space, so you do not manually have to find the half way point on two columns. The list is provided by |content= or closed with {{div col end}}.",
    "params": {
"params": {
        "colwidth": {
"colwidth": {
            "label": "colwidth",
"label": "Column width",
            "description": "Specifies the width of columns, and determines dynamically the number of columns based on screen width; more columns will be shown on wider displays. This overrides the 'cols' setting.",
"description": "Specifies the width of columns, and determines dynamically the number of columns based on screen width; more columns will be shown on wider displays.",
            "type": "string",
"type": "string",
            "aliases": ["1"],["Colwidth"], ["ColWidth"],
"example": "22em",
            "required": false
"default": "30em"
        },
},
        "cols": {
"rules": {
            "label": "cols",
"label": "Rules",
            "description": "Specifies the number of columns.",
"description": "Produces vertical rules between the columns if set to yes.",
            "type": "string",
"type": "string",
            "default": "2",
"example": "yes"
            "aliases": ["2"], ["Cols"],
},
            "required": false
"gap": {
        },
"label": "Gap size",
        "rules": {
"description": "Specifies the space between the content of adjacent columns.",
            "label": "rules",
"type": "string",
            "description": "Produces vertical rules between the columns if set to yes.",
"example": "2em"
            "type": "string",
},
            "aliases": ["Rules"],
"class": {
            "required": false
"label": "HTML class",
        },
"description": "Specifies any class or multiple space-delimited classes.",
        "gap": {
"type": "string",
            "label": "gap",
"example": "plainlist nowrap"
            "description": "Specifies the space between the content of adjacent columns.",
},
            "type": "string",
"style": {
            "aliases": ["Gap"],
"label": "CSS style",
            "required": false
"description": "Specifies any custom styling.",
        },
"type": "string"
        "small": {
},
            "label": "small",
"content": {
            "description": "Sets text size to 90%.",
"label": "Content",
            "type": "string",
"description": "Specifies the content to divide into columns",
            "aliases": ["Small"],
"type": "content"
            "required": false
},
        },
"small": {
        "style": {
"label": "Small font",
            "label": "style",
"description": "Use a smaller font size (90%)",
            "description": "Specifies any custom styling.",
"example": "yes",
            "type": "string",
"type": "string"
            "aliases": ["Style"],
}
            "required": false
}
        }
    }
}
}
</templatedata>
</templatedata>
Line 121: Line 364:


==Redirects==
==Redirects==
* {{tl|Div col start}}
{{#ifeq:{{PAGENAME}}|Div col/doc|Redirects to {{tl|div col}}:}}
{{#ifeq:{{ROOTPAGENAME}}|Div col|
* {{tlx|col div}}
* {{tlx|colbegin}} (but '''not''' {{tlx|col begin}} or {{tlx|col-begin}})
* {{tlx|cols}}
* {{tlx|div col start}}
* {{tlx|div col begin}}
* {{tlx|div-col}}
* {{tlx|palmares start}}
}}<!--
-->{{#ifeq:{{PAGENAME}}|Div col/doc|<nowiki />
Redirects to {{tl|Div col end}}:}}<!--
-->{{#switch:{{PAGENAME}}|Div col end|Div col/doc=
*{{tlx|col div end}}
*{{tlx|colend}} (but '''not''' {{tlx|Col end}})
*{{tlx|div end}}
*{{tlx|Divcol-end}}
*{{tlx|Divcolend}}
*{{tlx|Divend}}
*{{tlx|End div col}}
*{{tlx|EndDivCol}}
*{{tlx|End of solid block}}
}}


==See also==
==See also==
{{Column-generating template families}}
* {{tl|refbegin}} and {{tl|refend}} (for columns in manual lists of references)
{{column-generating template families}}


<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox |
<includeonly>{{Sandbox other|
| <!-- CATEGORIES BELOW THIS LINE, PLEASE: -->
| <!-- CATEGORIES BELOW THIS LINE, PLEASE: -->
[[Category:Table and column templates]]
[[Category:Multi-column templates]]
 
[[Category:Templates that add a tracking category]]
<!--?:-->{{#switch:{{PAGENAME}} |Div col= |Div col end=}}
<!--?:-->{{#switch:{{PAGENAME}} |div col= |div col end=}}
[[es:Plantilla:Div col]]
}}</includeonly>
}}</includeonly>
Anonymous user