{{#ifeq:doc |doc
|
{{#ifeq:show |show
| {{#invoke:Message box|mbox}}
}}{{#if: |
| {{#ifexist:Template:Center
| [[Category:{{#switch:Template |Template=Template |Module=Module |User=User |#default=Wikipedia}} documentation pages]]
|
}}
}}
|
}}
{{#invoke:High-use|main|1=|2=|info=|demo=|form=|expiry=|system=}}
Description[edit]
It is to center elements on a page. See also Template:Align for more options and flexibility.
Usage[edit]
{{#invoke:Labelled list hatnote|labelledList|See also}}
{{#if: ||+ {{{title}}}}} {{#if: || Markup | Renders as
}}{{safesubst:#invoke:For loop|main}} |
To do this without a template, simply use the following code: <syntaxhighlight lang="HTML">
</syntaxhighlight> To center a table, see Help:TABLECENTER.
Notes:
- If the markup to be centered includes an equals sign, the markup must be preceded by
1=. Example:{{Center|1=the <span style="color:red">red</span> one}}. - If the markup to be centered includes a displaying pipe, the pipe must be escaped as
{{!}}or|.
Tables[edit]
Using {{#Invoke:Template link general|main|nolink=yes|code=yes|nowrap=yes}} / {{#Invoke:Template link general|main|nolink=yes|code=yes|nowrap=yes}} / {{#Invoke:Template link general|main|nolink=yes|code=yes|nowrap=yes}}
| Header text | ||||
|---|---|---|---|---|
| Left | Left
|
}} || Center || {{safesubst:#ifeq:Right|Right
|
Right
|
}} |
Using {{#Invoke:Template link general|main|nolink=yes|code=yes|nowrap=yes}} / {{#Invoke:Template link general|main|nolink=yes|code=yes|nowrap=yes}} / {{#Invoke:Template link general|main|nolink=yes|code=yes|nowrap=yes}}
| Header text | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{#switch: left | left = Left
|
right = Left
|
center = Left
|
#default = Error in Template:Align: the alignment setting "left" is invalid.
}} || {{#switch: center |
left = Center
|
right = Center
|
center = Center
|
#default = Error in Template:Align: the alignment setting "center" is invalid.
}} || {{#switch: right |
left = Right
|
right = Right
|
center = Right
|
#default = Error in Template:Align: the alignment setting "right" is invalid.
}} |
Tracking category[edit]
Pages, which use {{Center}} without an argument, are added to the [[:Category:{{#invoke:string|replace|1=Pages using center with no arguments|2=^:?[Cc]ategory:|3=|plain=false}}|{{#if:|{{{name}}}|Category:{{#invoke:string|replace|1=Pages using center with no arguments|2=^:?[Cc]ategory:|3=|plain=false}}}}]] (0).
TemplateData[edit]
|=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CCenter%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}} |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|no|C|c}}lick here] to see a monthly parameter usage report for {{#if:|[[Template:]]|this template}}{{#ifeq:{{safesubst:#switch: y
|no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:|its|this}} TemplateData}}.
|None|none=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CCenter%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}} |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|no|P|p}}arameter usage report]{{#ifeq:{{safesubst:#switch: y
|no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:|its|this}} TemplateData}}
|for|For=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CCenter%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}} |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|no|P|p}}arameter usage report] for {{#if:|[[Template:]]|Template:Center}}{{#ifeq:{{safesubst:#switch: y
|no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:|its|this}} TemplateData}}.
|#default=[1]{{#ifeq:{{safesubst:#switch: y |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:|its|this}} TemplateData}} }}|This is the {{#if:|TemplateData|TemplateData}} for this template used by TemplateWizard, VisualEditor and other tools. {{#switch:
|=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CCenter%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}} |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|no|C|c}}lick here] to see a monthly parameter usage report for {{#if:|[[Template:]]|this template}}{{#ifeq:{{safesubst:#switch: y
|no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:|its|this}} TemplateData}}.
|None|none=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CCenter%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}} |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|no|P|p}}arameter usage report]{{#ifeq:{{safesubst:#switch: y
|no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:|its|this}} TemplateData}}
|for|For=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CCenter%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}} |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|no|P|p}}arameter usage report] for {{#if:|[[Template:]]|Template:Center}}{{#ifeq:{{safesubst:#switch: y
|no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:|its|this}} TemplateData}}.
|#default=[2]{{#ifeq:{{safesubst:#switch: y |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:|its|this}} TemplateData}} }}}}
TemplateData for Center
{{#invoke:Check for unknown parameters|check
|unknown={{#switch:
{{#if:
| {{{demospace}}}
| {{#ifeq:Template|Template
| template
| other
}}
}}
| template = | other | #default = }} |template=Template:TemplateData header |1 |nolink |noheader
|preview=
}}{{#switch:
{{#if:
| {{{demospace}}}
| {{#ifeq:Template|Template
| template
| other
}}
}}
| template = {{#if:{{#ifeq:{{#invoke:String|sublength|s=doc|i=0|len=7}}|sandbox|1}}{{#ifeq:doc|doc|1}}{{#invoke:String|match|Center/doc|/sandbox/styles.css$|plain=false|nomatch=}}||
}} | other | #default = }} <templatedata> { "params": { "1": { "label": "Content", "type": "content", "required": true, "description": "Content to be centered" }, "style": { "label": "Custom CSS" } }, "description": "A simple template to center-align content in tables and other places. Be aware that the center class is applied to this template, which means every element within the template has its left and right margins set to auto. This may harm some templates." } </templatedata>
See also[edit]
- {{Center block}}
- {{align}}
- {{right}}, {{left}} and {{justify}}
- {{Image frame}}