Help:畫廊
![]() | 本页為操作指南,用於介紹中文维基百科社群的一些实现和操作方式。 本文只是論述,不屬於方針或指引。如果本指南與方針或指引起衝突或不一致,請以方針或指引的條文為準。 |
画廊标签可以以阵列或类似布局排列并显示图像,即图像可以按行和列显示,其原理是利用对<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) -->
使用说明
- Indiscriminate use of the
perrow
attribute is strongly discouraged, because it overrides flexible use of different display sizes and aspect ratios, ranging from mobile miniature to wide "cinema" screens. However, the attribute should be used when a fixed grid arrangement is appropriate, such as "before/after", "low/medium/high", or other systematic comparisons of images. - If
perrow
is omitted, the width is fluid: one row comprises as many images as will fit across the available width of the user's display, wrapping automatically to as many additional lines as needed. - Omitting
perrow
is now the recommended default. Prior to MediaWiki 1.17, the default was 4. - The default width and height are currently 120px. Images displayed by the
<Gallery>...</Gallery>
tag do not obey user viewing preferences. - The
packed
mode will automatically adjust image sizes to use available display space optimally. - Every line specifies an image file. The
File:
prefix is unnecessary. - Captions are optional and are separated from file name by a vertical bar ("|").
- A common mistake is to forget the closing
</gallery>
tag. - When using, note that many parameters, specifically those relating to visual appearance, may not apply or work as expected to certain skins (notably the Minerva skin used by the mobile site).
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:
- Sample gallery
-
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