帮助:Gallery tag
本页为操作指南,用于介绍中文维基百科社群的一些实现和操作方式。 本文只是论述,不属于方针或指引。如果本指南与方针或指引起冲突或不一致,请以方针或指引的条文为准。 |
画廊标签可以以阵列或类似布局排列并显示图像,即图像可以按行和列显示,其原理是利用对<gallery>...</gallery>
标签的语法分析将Wikitext转化为HTML。请注意,不同的屏幕和浏览器显示尺寸或有可能影响可读性。
参数
编辑参数需要放在gallery
,和HTML结束标签之前,并且和前面间隔一个空格:
<gallery 具体参数...>
mode=
traditional
默认模式nolines
无边框,减少图像偏移,图注居中packed
图像等高,图注居中packed-overlay
类似packed,但图注会在透明浮框里居中显示packed-hover
类似packed-overlay,但浮框仅在鼠标悬停时显示slideshow
幻灯片模式
caption=
在画廊上方添加整体图注widths=
设定图像固定宽度(单位:px), mode=packed/packed-overlay/packed-hover/slideshow时无效heights=
设定图像固定高度(单位:px),mode=slideshow时无效perrow=
每行图片数量,mode=packed/packed-overlay/packed-hover/slideshow时无效,详见使用说明showfilename=yes
显示图片文件名class=
例如class="class_name"
style=
例如style="css-attr1:xx;..."
mode=slideshow在2023年已失效
编辑Galleries using both mode=slideshow
and caption=...
are broken as of mid January 2023. It has been reported at Wikipedia:Village pump (technical)#gallery mode="slideshow" broken and phab:T326990 with work on a fix. In the meantime, consider commenting out caption
like this so it's easy to revert later:
<gallery mode=slideshow <!--caption=... (slideshow captions were broken in January 2023) -->
使用说明
编辑- 应该避免使用
perrow
参数,因为它不能根据图像原有尺寸和长宽比例灵活布局,在移动设备或大屏设备上可能会导致图像放缩失当。如果图像适合固定比例网格布局时,例如图像有“前/后”“低/中/高”等效对比及其它同类情况,最好使用这一参数。 - 如果
perrow
省略,图像宽度自会遵循自适应布局,自动根据用户显示宽带决定每行图片数量。 - Omitting
perrow
is now the recommended default. Prior to MediaWiki 1.17, the default was 4. - 默认长宽120px,在
<Gallery>...</Gallery>
内的图像并不遵循用户偏好。 packed
模式下,图片总会自动调整大小,以更加有效利用显示空间- 每一行都需要文件名,没有必要加上文件前缀
File:
。 - 图注可选,在文件名后添加竖线 ("|"),在竖线右侧写图注。
- 一定、一定、一定要记得结尾的
</gallery>
标签。 - 使用时主要许多参数,尤其是和图像外观有关的参数,并不会在所有网站外观下工作(特别是移动版的Minerva外观)。
Loading in images
编辑When loading in images using the Insert > Images and media, you will get the following:
{{tsl|en|File:Name of file||thumb|Caption}}
In a gallery, you must remove all brackets ("[" or "]") (Except in wikilinks that are embedded within captions). You must also remove the |thumb
. Finally, remove the File:
prefix. You will be left with the following:
Name of file|Caption
This is acceptable to the gallery. If you do not want to include a caption, remove |Caption
.
语法
编辑There are several "modes" of galleries.
traditional:
"Traditional" mode is currently the default, and, as such, need not be specified. The basic syntax is:
<gallery>
Detroit Publishing Co. - A Yeoman of the Guard (N.B. actually a Yeoman Warder), full restoration.jpg|1
Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|2
Thurston, the famous magician - East Indian Rope Trick.jpg|3
Joseph Ferdinand Keppler - The Pirate Publisher - Puck Magazine - Restoration by Adam Cuerden.jpg|4
</gallery>
Which gives:
-
1
-
2
-
3
-
4
If you want to make sure that any future changes to the default gallery mode will keep this style of gallery, you may specify "mode=traditional", similar to the examples below.
nolines:
By specifying the "nolines" mode parameter, the boxes are removed. Using the same syntax as before, but replacing <gallery>
with <gallery mode=nolines>
we get:
-
1
-
2
-
3
-
4
packed:
Changing <gallery>
to <gallery mode=packed>
produces a centered gallery, with slightly to significantly less space around each image (depending on its relative width and height), as shown below. It may relatively enlarge some images that were smaller in the above views.
-
1
-
2
-
3
-
4
For lengthy captions under narrow images, it's probably best to add a heights=
parameter to make the images somewhat larger, as the default small size, can lead to ugly images. See below.
Packed-overlay:
This uses <gallery mode=packed-overlay>
to produce captions overlaying the bottom of the image. The captions are probably best kept short.
Packed-hover:
This uses <gallery mode=packed-hover>
. Hover your mouse over the images below. NOTE: This defaults to the behaviour of packed-overlay on the mobile site.
-
The captions
-
appear when
-
you
-
mouse over
扩展语法
编辑Besides mode, the extended syntax is (see gallery tag help and hereafter for full list of parameters):
<gallery caption="Sample gallery" widths="180px" heights="120px" >
Wiki.png|Captioned
Wiki.png|alt=The Wikipedia logo|Captioned with alt text
Wiki.png|{{tsl|en|Help:Contents/Links||Links}} can be put in captions.
Wiki.png|Full [[MediaWiki]]<br/>[[句法|syntax]] may now be used...
</gallery>
Which produces:
-
Captioned
-
Captioned with alt text
-
Links can be put in captions.
The widths=
and perrow=
parameters do nothing in the packed, packed-overlay, or packed-hover modes.
However, the heights=
parameter can be extremely useful in these modes. This parameter specifies the initial height to render every image thumbnail, before images are possibly scaled up (keeping their size ratio) by JavaScript to fill rows; when needed the Javascript will query the image server to get resized thumbnails for several scales between 100% (the initial height specified) and about 125%. This gives good-looking galleries that can fill pages even when their size ratio are not exactly the same and allows using the actual area available for displaying on narrow mobile and large notebook/desktop/TV, and printing on various paper formats. (This mode also allows horizontally auto-scrollable galleries by embedding them in a large container within a scrollable container sized to fit the page width).
For example, take the following:
<gallery mode=packed>
Detroit Publishing Co. - A Yeoman of the Guard (N.B. actually a Yeoman Warder), full restoration.jpg|A Yeoman Warder, from a Victorian-era {{tsl|en|photochrom||photochrom}}
Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.
Thurston, the famous magician - East Indian Rope Trick.jpg|[[霍華·薩斯頓|Howard Thurston]] performing the [[印度通天绳|Indian rope trick]]
Joseph Ferdinand Keppler - The Pirate Publisher - Puck Magazine - Restoration by Adam Cuerden.jpg|"The Pirate Publisher", a satire of copyright infringement from the magazine ''[[Puck (雜誌)|Puck]]''.
</gallery>
gives:
-
A Yeoman Warder, from a Victorian-era photochrom
-
The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.
-
Howard Thurston performing the Indian rope trick
-
"The Pirate Publisher", a satire of copyright infringement from the magazine Puck.
As you can see, the narrowness of the image distorts the caption. This may easily be fixed by adding the heights=
parameter, as such.
<gallery mode=packed heights=200px>
Detroit Publishing Co. - A Yeoman of the Guard (N.B. actually a Yeoman Warder), full restoration.jpg|A Yeoman Warder, from a Victorian-era {{tsl|en|photochrom||photochrom}}
Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.
Thurston, the famous magician - East Indian Rope Trick.jpg|[[霍華·薩斯頓|Howard Thurston]] performing the [[印度通天绳|Indian rope trick]]
Joseph Ferdinand Keppler - The Pirate Publisher - Puck Magazine - Restoration by Adam Cuerden.jpg|"The Pirate Publisher", a satire of copyright infringement from the magazine ''[[Puck (雜誌)|Puck]]''.
</gallery>
gives:
-
A Yeoman Warder, from a Victorian-era photochrom
-
The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.
-
Howard Thurston performing the Indian rope trick
-
"The Pirate Publisher", a satire of copyright infringement from the magazine Puck.
Other advice for using packed mode is to keep captions for particularly narrow images as short as is convenient.
Captions
编辑For all modes except traditional, captions are centered. To left-align the captions, specify the CSS declaration text-align:left
in the style=
attribute:
<gallery mode=packed heights=150px style="text-align:left">
Detroit Publishing Co. - A Yeoman of the Guard (N.B. actually a Yeoman Warder), full restoration.jpg|A Yeoman Warder, from a Victorian-era {{tsl|en|photochrom||photochrom}}
Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.
Joseph Ferdinand Keppler - The Pirate Publisher - Puck Magazine - Restoration by Adam Cuerden.jpg|"The Pirate Publisher", a satire of copyright infringement from the magazine ''[[Puck (雜誌)|Puck]]''.
</gallery>
gives:
-
A Yeoman Warder, from a Victorian-era photochrom
-
The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.
-
"The Pirate Publisher", a satire of copyright infringement from the magazine Puck.
To center a caption when other options are ineffective, perhaps the most-reliable alternative is to use:
yourimage.jpg | <div style="text-align: center;">yourcaption</div>
居中
编辑To center a gallery use class="center"
:
<gallery class="center"> Detroit Publishing Co. - A Yeoman of the Guard (N.B. actually a Yeoman Warder), full restoration.jpg|1 Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|2 Thurston, the famous magician - East Indian Rope Trick.jpg|3 Joseph Ferdinand Keppler - The Pirate Publisher - Puck Magazine - Restoration by Adam Cuerden.jpg|4 </gallery>
Which gives:
-
1
-
2
-
3
-
4
The use of the perrow
attribute will cause this to not work. Where a specific number of images per row is desired, use separate <gallery>
elements. Centered galleries are the default for most variant gallery modes.
参见
编辑- Wikipedia:文件使用方针
- Wikipedia:图像
- Wikipedia:格式手册/亲和力
- 维基百科:扩展图像语法
- Template:gallery(讨论 - 链入页面 - 编辑)
- More gallery options: see the drop-down box for more CSS gallery code
- mw:Help:Images#Rendering a gallery of images