Template:Float/doc: Difference between revisions

Nothing to hide, but nothing to show you either.
Jump to navigation Jump to search
Content added Content deleted
(Code example too <small>)
m (35 revisions imported from wikipedia:Template:Float/doc)
 
(22 intermediate revisions by 12 users not shown)
Line 1: Line 1:
{{documentation subpage}}
{{Documentation subpage}}
<!-- Please add categories to the /doc subpage, and interwikis at Wikidata (see Wikipedia:Wikidata) -->
<!---PLEASE ADD METADATA TO THE <includeonly> SECTION AT THE BOTTOM OF THIS PAGE--->


== Description ==
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.
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 {{tl|align}}. For floating images, boxes, and other elements, see {{tl|stack}}.
: <code><nowiki>{{</nowiki>'''float'''|''top''= |''right''= |''bottom''= |''left''= |'''''item'''''}}</code>, where ''top'' and ''right'' default to zero.
: <code><nowiki>{{</nowiki>'''float'''|'''''item'''''}}</code> with default positioning ''top'':0, ''right'':0 (i.e. ''item'' floats on righthand side).


== Usage ==
''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 (e.g. <code><nowiki>{{</nowiki>float|top=2em|left=2em|width=10em|"Blah"}}</code>&nbsp;). Note that if any values other than zero for ''top'' and ''right'' are required, they need to be specified.
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.


More configuration:
===Examples===
* <code><nowiki>{{float |width= |height= |top= |right= |bottom= |left= |</nowiki>{{bigger|{{smallcaps|item}}}}}}</code>
'''One-line [[Template:Navbox|navbox]] using its image parameter:'''

<code>{{bigger|{{smallcaps|item}}}}</code> is required. You must specify what text or element to float or it will throw an error.

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 = expanded
| state = uncollapsed
|title = [[Imperial Japanese Navy]]
| title = [[Imperial Japanese Navy]]
| listclass = hlist
|image = [[Image:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]
| image = [[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]
|list1 = <div>
| list1 =
[[Imperial Japanese Navy admirals|Admirals]]{{·}}
[[Battles of the Imperial Japanese Navy|Battles]]{{·}}
* [[Imperial Japanese Navy admirals|Admirals]]
[[List of ships of the Japanese Navy|Ships]]{{·}}
* [[Battles of the Imperial Japanese Navy|Battles]]
[[List of aircraft of the Japanese Navy|Aircraft]]{{·}}
* [[List of ships of the Japanese Navy|Ships]]
[[List of weapons of the Japanese Navy|Weapons]]
* [[List of aircraft of the Japanese Navy|Aircraft]]
* [[List of weapons of the Japanese Navy|Weapons]]
</div>
}}
}}
{{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
| 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]]
}}
</pre>
{{Hidden end}}


=== Example 2 (with float) ===
'''Same navbox using <code><nowiki>{{float}}</nowiki></code>:'''
We use {{tlf|float}} instead of the navbox's image parameter:
{{Navbox
{{Navbox
|name = Float/doc
| name = Float/doc
|state = expanded
| state = uncollapsed
|title = [[Imperial Japanese Navy]]
| title = [[Imperial Japanese Navy]]
|list1 = <div>
| listclass = hlist
{{float|top=-0.1em|[[Image: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]]
[[List of ships of the Japanese Navy|Ships]]{{·}}
* [[List of ships of the Japanese Navy|Ships]]
[[List of aircraft of the Japanese Navy|Aircraft]]{{·}}
* [[List of aircraft of the Japanese Navy|Aircraft]]
[[List of weapons of the Japanese Navy|Weapons]]
* [[List of weapons of the Japanese Navy|Weapons]]
</div>
}}
}}
{{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|[[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}}


=== Example 3 (with float and custom values) ===
Note how the links in the latter are centered relative to the whole template, unlike the former.
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
| 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]]
}}
{{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
| 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]]
}}
</pre>
{{Hidden end}}


== See also ==
* {{tl|align}}
* {{tl|stack}}
* {{tl|clear}}


<includeonly>
<includeonly>{{sandbox other||
<!-- Add categories below this line, and interwikis at Wikidata -->
[[Category:Wikipedia formatting and function templates|{{PAGENAME}}]]
[[Category:Positioning templates]]
[[pt:Predefinição:Float]]
</includeonly>
}}</includeonly>

Latest revision as of 16:10, 25 June 2021

Description[edit source]

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[edit source]

These are the standard usage:

  • {{float|item}} floats item on the rightmost of a page/area.
  • {{float|left|item}} floats item on the leftmost of a page/area.

More configuration:

  • {{float |width= |height= |top= |right= |bottom= |left= |item}}

item 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[edit source]

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[edit source]

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)[edit source]

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)[edit source]

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)[edit source]

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[edit source]

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[edit source]