Difference between revisions of "Template:Float/doc"

From blackwiki
Jump to navigation Jump to search
imported>Frietjes
imported>Redrose64
(→‎See also: rm strange syntax)
 
(15 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{documentation subpage}}
+
{{Documentation subpage}}
<!---PLEASE ADD METADATA TO THE <includeonly> SECTION AT THE BOTTOM OF THIS PAGE--->
+
<!-- Please add categories to the /doc subpage, and interwikis at Wikidata (see Wikipedia:Wikidata) -->
  
Use <code><nowiki>{{float}}</nowiki></code> to position items such as images so they do not affect the alignment or formatting of other items (e.g. text) nearby.
+
== Description ==
 +
It is used to position text or elements to the rightmost/leftmost of a page/area, without changing the alignment or formatting of other text and elements nearby.
  
: <code><nowiki>{{</nowiki>'''float'''|''top''= |''right''= |''bottom''= |''left''= |'''''item'''''}}</code>, where ''top'' and ''right'' default to zero.
+
For aligning text in general, see {{tl|align}}.  For floating images, boxes, and other elements, see {{tl|stack}}.
: <code><nowiki>{{</nowiki>'''float'''|'''''item'''''}}</code> with default positioning ''top'':0, ''right'':0 (i.e. ''item'' floats on righthand side).
 
  
''item'' is the only required parameter. The optional parameters ''top'', ''right'', ''bottom'', ''left'' indicate how far from their respective positions the ''item'' is to be positioned. The ''width'' of the item may also be specified. Any units may be used so long as they are specified{{ndash}}e.g. <code><nowiki>{{</nowiki>float|top=2em|left=2em|width=10em|"Blah"}}</code>. Note that if any values other than zero for ''top'' and ''right'' are required, they need to be specified.
+
== Usage ==
 +
These are the standard usage:
 +
* <code><nowiki>{{float|</nowiki>{{bigger|{{smallcaps|item}}}}}}</code> floats {{smallcaps|item}} on the rightmost of a page/area.
 +
* <code><nowiki>{{float|left|</nowiki>{{bigger|{{smallcaps|item}}}}}}</code> floats {{smallcaps|item}} on the leftmost of a page/area.
  
===Examples===
+
More configuration:
Note how the links in the second two examples are centered relative to the whole template, unlike in the first example.
+
* <code><nowiki>{{float |width= |height= |top= |right= |bottom= |left= |</nowiki>{{bigger|{{smallcaps|item}}}}}}</code>
  
; Example 1
+
<code>{{bigger|{{smallcaps|item}}}}</code> is required. You must specify what text or element to float or it will throw an error.
One-line [[Template:Navbox|navbox]] using its image parameter:
+
 
 +
All parameters are optional. The parameters {{para|width}} and {{para|height}} are to indicate the width/height of the <code><nowiki><div></nowiki></code> element. <!--Unnecessary?: Note that if any values other than zero for ''top'' and ''right'' are required, they need to be specified.-->
 +
 
 +
The optional parameters {{para|top}}, {{para|right}}, {{para|bottom}} and {{para|left}} are to indicate how far from their respective positions the item is to be positioned.
 +
 
 +
Any established HTML/CSS units may be used, for example, <code><nowiki>{{float |top=2.0em |left=2px |width=10em | the content to float}}</nowiki></code>.
 +
 
 +
=== Beware ===
 +
Beware when using this template in navboxes. Please ensure whatever it floats (e.g. an image) does not float over other elements or text, even after the navbox is resized.
 +
 
 +
To align centered lists in a navbox with an image, see the [[#Alternatives for navigational boxes|alternatives for navigational boxes]] section below.
 +
 
 +
== Examples ==
 +
Note how the links in the second two examples are centered relative to the whole template, unlike those in the first example.
 +
 
 +
=== Example 1 (without float) ===
 +
This is a [[Template:Navbox|navbox]] using its image parameter:
 
{{Navbox
 
{{Navbox
| name = Float/doc
+
| name = Float/doc
 
| state = uncollapsed
 
| state = uncollapsed
 
| title = [[Imperial Japanese Navy]]
 
| title = [[Imperial Japanese Navy]]
Line 27: Line 46:
 
* [[List of weapons of the Japanese Navy|Weapons]]
 
* [[List of weapons of the Japanese Navy|Weapons]]
 
}}
 
}}
{{hidden begin|title=Code for Example 1|toggle = left}}
+
{{Hidden begin |showhide=left |title=The code used in the above example}}
 
<pre>
 
<pre>
 
{{Navbox
 
{{Navbox
| name = Float/doc
+
| name = Float/doc
 
| state = uncollapsed
 
| state = uncollapsed
 
| title = [[Imperial Japanese Navy]]
 
| title = [[Imperial Japanese Navy]]
Line 43: Line 62:
 
}}
 
}}
 
</pre>
 
</pre>
{{hidden end}}
+
{{Hidden end}}
  
; Example 2
+
=== Example 2 (with float) ===
Same navbox using <code><nowiki>{{float}}</nowiki></code> instead of the image parameter:
+
We use {{tlf|float}} instead of the navbox's image parameter:
 
{{Navbox
 
{{Navbox
| name = Float/doc
+
| name = Float/doc
 
| state = uncollapsed
 
| state = uncollapsed
 
| title = [[Imperial Japanese Navy]]
 
| title = [[Imperial Japanese Navy]]
 
| listclass = hlist
 
| listclass = hlist
| list1 = {{float|top=-0.1em|[[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]}}
+
| list1 = {{float|[[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]}}
 
* [[Imperial Japanese Navy admirals|Admirals]]
 
* [[Imperial Japanese Navy admirals|Admirals]]
 
* [[Battles of the Imperial Japanese Navy|Battles]]
 
* [[Battles of the Imperial Japanese Navy|Battles]]
Line 59: Line 78:
 
* [[List of weapons of the Japanese Navy|Weapons]]
 
* [[List of weapons of the Japanese Navy|Weapons]]
 
}}
 
}}
{{hidden begin|title=Code for Example 2|toggle = left}}
+
{{Hidden begin |showhide=left |title=The code used in the above example}}
 
<pre>
 
<pre>
 
{{Navbox
 
{{Navbox
| name = Float/doc
+
| name = Float/doc
 
| state = uncollapsed
 
| state = uncollapsed
 
| title = [[Imperial Japanese Navy]]
 
| title = [[Imperial Japanese Navy]]
 
| listclass = hlist
 
| listclass = hlist
| list1 = {{float|top=-0.1em|[[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]}}
+
| list1 = {{float|[[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]}}
 
* [[Imperial Japanese Navy admirals|Admirals]]
 
* [[Imperial Japanese Navy admirals|Admirals]]
 
* [[Battles of the Imperial Japanese Navy|Battles]]
 
* [[Battles of the Imperial Japanese Navy|Battles]]
Line 74: Line 93:
 
}}
 
}}
 
</pre>
 
</pre>
{{hidden end}}
+
{{Hidden end}}
  
; Example 3
+
=== Example 3 (with float and custom values) ===
Same navbox using its image parameter and liststyle with padding-left set to the image width:
+
We use {{tlf|float}} with a custom value of {{para|top}} this time:
 +
{{Navbox
 +
| name = Float/doc
 +
| state = uncollapsed
 +
| title = [[Imperial Japanese Navy]]
 +
| listclass = hlist
 +
| list1 = {{float|top=0.5em|[[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]}}
 +
* [[Imperial Japanese Navy admirals|Admirals]]
 +
* [[Battles of the Imperial Japanese Navy|Battles]]
 +
* [[List of ships of the Japanese Navy|Ships]]
 +
* [[List of aircraft of the Japanese Navy|Aircraft]]
 +
* [[List of weapons of the Japanese Navy|Weapons]]
 +
}}
 +
{{Hidden begin |showhide=left |title=The code used in the above example}}
 +
<pre>
 +
{{Navbox
 +
| name = Float/doc
 +
| state = uncollapsed
 +
| title = [[Imperial Japanese Navy]]
 +
| listclass = hlist
 +
| list1 = {{float|top=0.5em|[[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]}}
 +
* [[Imperial Japanese Navy admirals|Admirals]]
 +
* [[Battles of the Imperial Japanese Navy|Battles]]
 +
* [[List of ships of the Japanese Navy|Ships]]
 +
* [[List of aircraft of the Japanese Navy|Aircraft]]
 +
* [[List of weapons of the Japanese Navy|Weapons]]
 +
}}
 +
</pre>
 +
{{Hidden end}}
 +
 
 +
=== Alternatives for navigational boxes ===
 +
We use its image parameter and liststyle with padding-left set to the image width:
 
{{Navbox
 
{{Navbox
 
| name      = Float/doc
 
| name      = Float/doc
Line 92: Line 142:
 
* [[List of weapons of the Japanese Navy|Weapons]]
 
* [[List of weapons of the Japanese Navy|Weapons]]
 
}}
 
}}
{{hidden begin|title=Code for Example 3|toggle = left}}
+
{{Hidden begin |showhide=left |title=The code used in the above example}}
 
<pre>
 
<pre>
 
{{Navbox
 
{{Navbox
Line 109: Line 159:
 
}}
 
}}
 
</pre>
 
</pre>
{{hidden end}}
+
{{Hidden end}}
 +
 
 +
== See also ==
 +
* {{tl|align}}
 +
* {{tl|stack}}
 +
* {{tl|clear}}
  
<includeonly>
+
<includeonly>{{sandbox other||
[[Category:Wikipedia formatting and function templates]]
+
<!-- Add categories below this line, and interwikis at Wikidata -->
[[pt:Predefinição:Float]]
+
[[Category:Positioning templates]]
[[tr:Şablon:Float]]
+
}}</includeonly>
</includeonly>
 

Latest revision as of 12:13, 10 January 2020

Description

It is used to position text or elements to the rightmost/leftmost of a page/area, without changing the alignment or formatting of other text and elements nearby.

For aligning text in general, see {{align}}. For floating images, boxes, and other elements, see {{stack}}.

Usage

These are the standard usage:

More configuration:

Template:Smallcaps is required. You must specify what text or element to float or it will throw an error.

All parameters are optional. The parameters |width= and |height= are to indicate the width/height of the <div> element.

The optional parameters |top=, |right=, |bottom= and |left= are to indicate how far from their respective positions the item is to be positioned.

Any established HTML/CSS units may be used, for example, {{float |top=2.0em |left=2px |width=10em | the content to float}}.

Beware

Beware when using this template in navboxes. Please ensure whatever it floats (e.g. an image) does not float over other elements or text, even after the navbox is resized.

To align centered lists in a navbox with an image, see the alternatives for navigational boxes section below.

Examples

Note how the links in the second two examples are centered relative to the whole template, unlike those in the first example.

Example 1 (without float)

This is a navbox using its image parameter:

The code used in the above example
{{Navbox
| name = Float/doc
| state = uncollapsed
| title = [[Imperial Japanese Navy]]
| listclass = hlist
| image = [[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]
| list1 =
* [[Imperial Japanese Navy admirals|Admirals]]
* [[Battles of the Imperial Japanese Navy|Battles]]
* [[List of ships of the Japanese Navy|Ships]]
* [[List of aircraft of the Japanese Navy|Aircraft]]
* [[List of weapons of the Japanese Navy|Weapons]]
}}

Example 2 (with float)

We use {{float}} instead of the navbox's image parameter:

The code used in the above example
{{Navbox
| name = Float/doc
| state = uncollapsed
| title = [[Imperial Japanese Navy]]
| listclass = hlist
| list1 = {{float|[[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]}}
* [[Imperial Japanese Navy admirals|Admirals]]
* [[Battles of the Imperial Japanese Navy|Battles]]
* [[List of ships of the Japanese Navy|Ships]]
* [[List of aircraft of the Japanese Navy|Aircraft]]
* [[List of weapons of the Japanese Navy|Weapons]]
}}

Example 3 (with float and custom values)

We use {{float}} with a custom value of |top= this time:

The code used in the above example
{{Navbox
| name = Float/doc
| state = uncollapsed
| title = [[Imperial Japanese Navy]]
| listclass = hlist
| list1 = {{float|top=0.5em|[[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]}}
* [[Imperial Japanese Navy admirals|Admirals]]
* [[Battles of the Imperial Japanese Navy|Battles]]
* [[List of ships of the Japanese Navy|Ships]]
* [[List of aircraft of the Japanese Navy|Aircraft]]
* [[List of weapons of the Japanese Navy|Weapons]]
}}

Alternatives for navigational boxes

We use its image parameter and liststyle with padding-left set to the image width:

The code used in the above example
{{Navbox
| name      = Float/doc
| state     = uncollapsed
| title     = [[Imperial Japanese Navy]]
| listclass = hlist
| image     = [[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]
| liststyle = padding-left: 24px
| list1     =
* [[Imperial Japanese Navy admirals|Admirals]]
* [[Battles of the Imperial Japanese Navy|Battles]]
* [[List of ships of the Japanese Navy|Ships]]
* [[List of aircraft of the Japanese Navy|Aircraft]]
* [[List of weapons of the Japanese Navy|Weapons]]
}}

See also