Template:Optional style
Jump to navigation
Jump to search
This template uses Lua: |
This template is used on approximately 1,320,000 pages, or roughly 30% of all pages. To avoid major disruption and server load, any changes should be tested in the template's /sandbox or /testcases subpages, or in your own user subpage. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
Usage
Utility template for constructing optional style attributes. This is probably only useful in other templates.
It allows to create a style with any number of rules, omitting any not given (or blank) and omitting the entire style attribute if none are given.
This means that this:
{{#if:{{{padding-top|}}}{{{padding-bottom|}}}|style="{{#if:{{{padding-top|}}}|padding-top:{{{padding-top}}};}}{{#if:{{{padding-bottom|}}}|padding-bottom:{{{padding-bottom}}};}}"}}
becomes:
{{optional style | padding-top = {{{padding-top|}}} | padding-bottom = {{{padding-bottom|}}} }}
Parameters:
- Any given parameters are used as the CSS property name (e.g.
padding-top
). The parameter value is the property value (e.g. blank or2em
). - style: Pre-built CSS (i.e. like
padding-left:2em; padding-right:1em;
(the semicolons between items are important). Will be added at the end of the style, so it will override any other parameter (in this case, padding-left would be overridden by style.
Examples
Example
{{optional style | padding-top = 2em | padding-bottom = }}
style="padding-top:2em;"
Example: All parameters blank
{{optional style | padding-top = | padding-bottom = }}
Example: With a style parameter
{{optional style | padding-top = 4em; | padding-bottom = | style = padding-left:2em;padding-top:1em; }}
style="padding-top:4em;padding-left:2em;padding-top:1em;"
See also
- {{HTML attribute}}