Template:Center

From Wiki.CoreyBlair.US
Jump to navigation Jump to search
50px Template documentation[view] [edit] [history] [purge]

{{#ifeq:center |doc

    | 

{{#ifeq:show |show

|
        }}{{#if: |
         |   {{#ifexist:Template:Center
                  | [[Category:{{#switch:Template |Template=Template |Module=Module |User=User |#default=Wikipedia}} documentation pages]]
                  |
                 }}
        }}
    | 
   }}

A simple template to center-align content in tables and other places. Be aware that the center class is appllied to this template, which means every element within the template has its left and right margins set to auto. This may harm some templates.

Example

{{#if: ||+ {{{title}}}}} {{#if: |
Markup Renders as

}}{{#if: {{Center|Hello world!}}

{{Center|Hello world!}}
Hello world!
{{#if:Hello world!||}}
}}{{#if:  | 

}}{{#if:  | 

}}{{#if:  | 

}}{{#if:  | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}{{#if: | 

}}

To do this without a template, simply use the following code:

{{#switch:pair
 |c|close =
 |e|empty|s|single|v|void
 |o|open
 |p|pair = <div{{#if:class="center" style="width:auto; margin-left:auto; margin-right:auto;"| class="center" style="width:auto; margin-left:auto; margin-right:auto;"}}
}}{{#switch:pair
 |c|close = 
 |e|empty|s|single|v|void =  />
 |o|open = >
 |p|pair = {{#ifeq:div|!--||>}}...
}}{{#switch:pair
 |e|empty|s|single|v|void
 |o|open =
 |c|close
 |p|pair = {{#ifeq:div|!--|-->|</div>}}
}}

To center a table, see Help:TABLECENTER.

Table

Using {{#if:{{#if:||yes}} |}}{{#if:yes | |{{#if:|}} }}{{#if: |}}{{#if: |}}{{#if: | |{{}}{{#if: |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:l|: |Left |{{#switch:

                        |  = Template:{{#if:left|Left|Center}}
                        | #default = {{#if:left|Left|Template:Center}}
                     }}}}|}}{{#if: |{}}{{#if:left|left|{{#ifeq:Template|Template|Center|Template:Center}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |}}{{#if:{{#if:||yes}} |}} / {{#if:{{#if:||yes}}        |}}{{#if:yes | |{{#if:|}} }}{{#if:           |}}{{#if:    |}}{{#if:   | |{{}}{{#if:         |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:c|:  |Center |{{#switch:
                        |  = Template:{{#if:center|Center|Center}}
                        | #default = {{#if:center|Center|Template:Center}}
                     }}}}|}}{{#if: |{}}{{#if:center|center|{{#ifeq:Template|Template|Center|Template:Center}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |}}{{#if:{{#if:||yes}} |}} / {{#if:{{#if:||yes}}        |}}{{#if:yes | |{{#if:|}} }}{{#if:           |}}{{#if:    |}}{{#if:   | |{{}}{{#if:         |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:r|:  |Right |{{#switch:
                        |  = Template:{{#if:right|Right|Center}}
                        | #default = {{#if:right|Right|Template:Center}}
                     }}}}|}}{{#if: |{}}{{#if:right|right|{{#ifeq:Template|Template|Center|Template:Center}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |}}{{#if:{{#if:||yes}} |}}
Header text
Left
Left
}} ||
Center
{{#if:Center||}} || {{safesubst:#ifeq:Right|Right
Right

}}

Using {{#if:{{#if:||yes}} |}}{{#if:yes | |{{#if:|}} }}{{#if: |}}{{#if: |}}{{#if: | |{{}}{{#if: |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:a|: |Align |{{#switch:

                        |  = Template:{{#if:align|Align|Center}}
                        | #default = {{#if:align|Align|Template:Center}}
                     }}}}|}}{{#if: |{}}{{#if:align|align|{{#ifeq:Template|Template|Center|Template:Center}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |}}{{#if:{{#if:||yes}} |}} / {{#if:{{#if:||yes}}        |}}{{#if:yes | |{{#if:|}} }}{{#if:           |}}{{#if:    |}}{{#if:   | |{{}}{{#if:         |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:a|:  |Align |{{#switch:
                        |  = Template:{{#if:align|Align|Center}}
                        | #default = {{#if:align|Align|Template:Center}}
                     }}}}|}}{{#if: |{}}{{#if:align|align|{{#ifeq:Template|Template|Center|Template:Center}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |}}{{#if:{{#if:||yes}} |}} / {{#if:{{#if:||yes}}        |}}{{#if:yes | |{{#if:|}} }}{{#if:           |}}{{#if:    |}}{{#if:   | |{{}}{{#if:         |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:a|:  |Align |{{#switch:
                        |  = Template:{{#if:align|Align|Center}}
                        | #default = {{#if:align|Align|Template:Center}}
                     }}}}|}}{{#if: |{}}{{#if:align|align|{{#ifeq:Template|Template|Center|Template:Center}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |}}{{#if:{{#if:||yes}} |}}
Header text
{{#switch: left left =
Left
right =
Left
center =
Left
{{#if:Left
}} #default = Error in Template:Align: the alignment setting "left" is invalid.

}} || {{#switch: center

left =
Center
right =
Center
center =
Center
{{#if:Center
}} #default = Error in Template:Align: the alignment setting "center" is invalid.

}} || {{#switch: right

left =
Right
right =
Right
center =
Right
{{#if:Right
}} #default = Error in Template:Align: the alignment setting "right" is invalid.

}}

See also

{{#switch:

 {{#if:
 | {{#if:{{#titleparts:{{{page}}}|0|3}}
   | subsubpage    
   | {{#if:{{#titleparts:{{{page}}}|0|2}}
     | subpage
     | basepage
     }}
   }}
 | {{#if:{{#titleparts:Template:Center|0|3}}
   | subsubpage    
   | {{#if:{{#titleparts:Template:Center|0|2}}
     | subpage
     | basepage
     }}
   }}
 }}

| basepage =


| subpage = | subsubpage = }}