模板:Nowraplinks/doc

来自决策链云智库
< 模板:Nowraplinks
Zeroclanzhang讨论 | 贡献2024年1月22日 (一) 15:43的版本 (创建页面,内容为“{{Documentation subpage}} __NOTOC__ <!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE --> This is the {{tl|nowraplinks}} template. This template works in conjunction with {{tl|nowraplinks end}} to prevent word wraps (line breaks) inside links that include a space or spaces while allowing wraps between links and in normal text. This can be useful, for instance, in long lists of links. It is similar to {{tl|nowrap begin}}...{{tl|nowrap end}}.…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

This is the {{nowraplinks}} template.

This template works in conjunction with {{nowraplinks end}} to prevent word wraps (line breaks) inside links that include a space or spaces while allowing wraps between links and in normal text. This can be useful, for instance, in long lists of links. It is similar to {{nowrap begin}}...{{nowrap end}}.

Reading Wikipedia:Line-break handling is recommended before starting to use this template.

Usage

{{nowraplinks}}

[[This link will not wrap]] - [[This link also won't wrap]] -
[[And so on]] - But this sentence might word wrap.

{{nowraplinks end}}
{{nowraplinks | [[This link will not wrap]] - [[This link also won't wrap]] -
[[And so on]] - But this sentence might word wrap. }}

Both examples will render something like this:

This link will not wrap -
This link also won't wrap -
And so on - But this sentence
might word wrap.

But they will not render like this:

This link will not wrap - This link
shouldn't have wrapped - And so on -
But this sentence might word wrap.

Advanced usage

Most of the functionality in this template is implemented as a CSS class in common.css. That class can be used together with pretty much any HTML tag or any box to prevent links to word wrap. For instance like this:

<div class="nowraplinks"> Lots of text and links </div>

Or like this:

<span class="nowraplinks"> Lots of text and links </span>

If the nowraplinks class is applied in the header of a table it will prevent line wrapping of links in all cells in the table. Note that in a table header there usually is a need to apply several classes. Then the class names should be separated by spaces in the class tag, not by commas or semicolons. Like this:

{| class="wikitable nowraplinks"
|
[[This link will not wrap]]{{·}} 
[[This link also won't wrap]]{{·}} 
[[And so on]]{{·}} 
But this sentence might word wrap.
|
[[This link will not wrap]]{{·}} 
[[This link also won't wrap]]{{·}} 
[[And so on]]{{·}} 
But this sentence might word wrap.
|}

It will render this:

To really see the nowrap effect on the links above you can drag the width of your web browser window so it becomes smaller and smaller.

Technical details

The actual code that does the job is this CSS code in Common.css.

.nowraplinks a,
.nowraplinks .selflink { 
  white-space: nowrap;
}

It simply means that any white-space inside links (HTML A tags) and bold "links" to the page itself are not allowed to wrap.

It is then invoked like this:

<span class="nowraplinks"> Lots of text and links </span>

That span code is what the {{nowraplinks}} and {{nowraplinks end}} tags are packaging in an easy to use way.

The standard navboxes use the .nowraplinks class, thus automatically handling most wrapping problems in those navboxes.

See also

模板:List of nowrap-like templates