Template:Center/doc

From Wikibooks, open books for an open world
Jump to navigation Jump to search

This utility template centers text inside an HTML <div>...</div> box that is wrapped around the <span>...</span> tags inside which is the text you supplied to the template's single, unnamed parameter, |1=. The <span>...</span> tags have 0.75em of padding on all sides and the <div>...</div> box has margins of 1em set above and below while the left and right margins are automatically sized to be identical (the result of calculating (viewport width - div width) / 2, which is the mechanism that actually centers the content on the page or inside whatever other smaller container it was placed in).

Usage[edit source]

{{Center|1=Your text goes here|style=optional inline CSS declarations}}

The |style= parameter is entirely optional and only intended to provide a way to overcome minor issues with text size and spacing. If used as intended, wrapped around text needing to be centered on the page, with any wikitext style desired applied outside the template, this template should be reliable and fairly versatile.

Example[edit source]

{{Center|1=You have not the power to bind me to either side of the page!}}

which produces:

You have not the power to bind me to either side of the page!

Caveats[edit source]

While not required, it's good to cultivate the habit of prepending 1= to the text you want centered, since that eliminates any chance of the template being broken by text that happens to have an equality sign (=) already present in it. Absent that situation and a few exceedingly rare others, it is perfectly acceptable to call it in its simplest form, e.g. {{Center|Read this in the middle of the page.}}.

Spacing[edit source]

The default padding and margin choices can be desirable in many cases as it sets off the text nicely from its surroundings, but that assumes it is the last (or only) text on a line—which can adversely affect wikitext using || separators in tables.

Text size[edit source]

It can also have undesirable 'enlarging' effects on the font used as a result of the double nested tag pairs, again, especially in tables. This is a good use for the style parameter; feeding it values of font-size: Xem;, where X is a decimal number whose default value is 1.0 (that represents the font size of the template's current output), can correct these issues. When X < 1, e.g. font-size: 0.95em;, the font size is reduced in proportion to the amount subtracted from 1 to achieve X, in this example a reduction of 5%. The reverse holds true for values of X that are > 1, if you need to enlarge the text instead.

TemplateData[edit source]

This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. Click here to see a monthly parameter usage report for this template based on this TemplateData.

TemplateData for Center

Formatting template that centers text on the page or inside of whatever container the template is placed within; a drop-in replacement for the long-deprecated <center>...</center> tags of yore.

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
Input text1 content text

The text you wished to appear centered wherever this template is placed

Example
Center me.
Stringrequired
Inline CSSstyle

Any extra inline CSS3 style definitions can be supplied to this parameter for inclusion in the <div>...</div> wrapper tags (don't forget to include the semicolon at the end of each one)

Example
font-size: 1.1em; font-weight: bold;
Lineoptional