Template:Nowrap/doc: Difference between revisions
(Added: "{{nobr}} and {{nobreak}} redirect here." to "Technical details". Don't want to advertice these deprecated aliases in a too visible place.) |
(A bunch of changes, including better first example.) |
||
Line 3: | Line 3: | ||
This is the {{tl|nowrap}} template. | This is the {{tl|nowrap}} template. | ||
This template prevents word wraps (line breaks) in text | This template prevents word wraps (line breaks) in text and links that contain spaces. | ||
Before you use this template you might want to read up on [[Wikipedia:Line break handling]]. | Before you use this template you might want to read up on [[Wikipedia:Line break handling]]. | ||
=== | === Usage === | ||
<pre> | |||
Lots of text {{nowrap|10 kg (22 lb)}} more text. | |||
</pre> | |||
It may render like this: | |||
: | :Lots of text 10 kg (22 lb) | ||
:more text. | |||
Or like this: | |||
:Lots of text | |||
:10 kg (22 lb) more text. | |||
But it will ''not'' render like this: | |||
:Lots of text 10 kg (22 | |||
:lb) more text. | |||
=== Handling interpreted characters === | === Handling interpreted characters === | ||
For text that includes an | [[Help:Template|Templates]] have problems to handle parameter data that contains equal signs "<code>=</code>" or vertical bars "<code>|</code>". In such cases consider using {{tl|nowrap begin}} + {{tl|nowrap end}} instead. But there are also workarounds: | ||
For text that includes an equal sign "=", precede the text with <code>1=</code>. For example: | |||
:<code><nowiki>{{nowrap|</nowiki>1=2 + 2 = 4}}</code> | :<code><nowiki>{{nowrap|</nowiki>1=2 + 2 = 4}}</code> | ||
Which renders: | Which renders this: | ||
:{{nowrap|1=2 + 2 = 4}} | :{{nowrap|1=2 + 2 = 4}} | ||
For text that includes a | For text that includes a vertical bar "|", escape the bar(s) with <code><nowiki>&#124;</nowiki></code> or <code><nowiki>{{!}}</nowiki></code>. For instance like this: | ||
:<code><nowiki>{{nowrap|</nowiki>&#124;2&#124; < 3}}</code> | :<code><nowiki>{{nowrap|</nowiki>&#124;2&#124; < 3}}</code> | ||
Line 29: | Line 42: | ||
:<code><nowiki>{{nowrap|{{!}}2{{!}} < 3}}</nowiki></code> | :<code><nowiki>{{nowrap|{{!}}2{{!}} < 3}}</nowiki></code> | ||
Which renders: | Which renders this: | ||
:{{nowrap||2| < 3}} | :{{nowrap||2| < 3}} | ||
Revision as of 08:43, 20 March 2008
This is the {{nowrap}} template.
This template prevents word wraps (line breaks) in text and links that contain spaces.
Before you use this template you might want to read up on Wikipedia:Line break handling.
Usage
Lots of text {{nowrap|10 kg (22 lb)}} more text.
It may render like this:
- Lots of text 10 kg (22 lb)
- more text.
Or like this:
- Lots of text
- 10 kg (22 lb) more text.
But it will not render like this:
- Lots of text 10 kg (22
- lb) more text.
Handling interpreted characters
Templates have problems to handle parameter data that contains equal signs "=
" or vertical bars "|
". In such cases consider using {{nowrap begin}} + {{nowrap end}} instead. But there are also workarounds:
For text that includes an equal sign "=", precede the text with 1=
. For example:
{{nowrap|1=2 + 2 = 4}}
Which renders this:
- 2 + 2 = 4
For text that includes a vertical bar "|", escape the bar(s) with |
or {{!}}
. For instance like this:
{{nowrap||2| < 3}}
Or like this:
{{nowrap|{{!}}2{{!}} < 3}}
Which renders this:
- |2| < 3
Technical details
The actual code that does the job is this HTML+CSS code:
<span style="white-space:nowrap">This text will not wrap</span>
Spaces at the beginning or end of your text will fall outside the no-wrap tag in the rendered text due to Wikimedia rendering mechanisms.
{{nobr}} and {{nobreak}} redirect here.
See also
- {{nowraplinks}} - Prevents wraps inside links and only allows wraps between the links and in normal text. Very useful for link lists and easy to use.
- {{nowrap begin}} - Prevents wraps in both text and links. For the trickier wrapping cases when you need full control, for instance in very complex link lists.
- Wikipedia:Line break handling - The how-to guide detailing how to handle word wraps (line breaks) on Wikipedia.