2

我正在尝试向我的 MediaWiki 网站上的页面添加一个信息框。

我的 common.css 中有这段代码:

.infobox { 
   border:1px solid #aaaaaa;
   background-color:#f9f9f9;
   padding:5px;
   font-size: 95%;
   border-collapse: collapse;
   margin-left: 20px;
}  

我在模板中有这个代码:信息框

<table class="infobox" align="right" bgcolor="#E1E1E1" style="width:20em; font-size:90%; text-align:left; border: 1px green solid;">
<caption style="text-align:center; font-size:140%;"><i><b>{{{name}}}</b></i></caption>
<tr>
<td colspan="2" style="text-align:center;" bgcolor="#E1E1E1">{{{image}}}</td>
</tr>
<tr>
<td colspan="2" bgcolor="#E1E1E1" style="text-align:center;">{{{imagecaption}}}</td>
<tr>
<th>Author</th>
<td>{{{author}}}</td>
</tr>
<tr>
<th>Publisher</th>
<td>{{{publisher}}}</td>
</tr>
<tr>
<th>Publication date</th>
<td>{{{publication}}}</td>
</tr>
<tr>
<th>Illustrator</th>
<td>{{{illustrator}}}</td>
</tr>
<tr>
<th>Genre</th>
<td>{{{genre}}}</td>
</tr>
<tr>
<th>Pages</th>
<td>{{{pages}}}</td>
</tr>
<tr>
<th>ISBN</th>
<td>{{{isbn}}}</td>
</tr>

最后,这是我插入 MediaWiki 页面的代码:

{{Infobox
| name = The Hitchhiker's Guide to the Galaxy
| image = [[Image:Hhgttg.jpg|150px]]
| image_caption = Movie Poster
| author = Douglas Adams
| country = United Kingdom
| language = English
| series = The Hitchhiker's Guide to the Galaxy
| genre = Science Fiction
| publisher = Pan Books
| release_date = 1979
| media_type = Paperback and hardcover
| pages = 180
| isbn = ISBN 0-330-25864-8
| followed_by = The Restaurant at the End of the Universe
}}

我遇到的问题是信息框在我的 MediaWiki 页面的右下角对齐。我宁愿让它出现在右上角,就像在维基百科的这个页面中一样:http ://en.wikipedia.org/wiki/Bill_Gates

我可以在我的代码中添加什么来实现这一点?

4

1 回答 1

3

哇,这很奇怪,但我想我已经设法找出原因:

您忘记关闭<table>模板内部。

正因为如此,当模板在页面的开头展开时,所有其余的页面内容最终都将被放置在未关闭的 HTML 表格中。但是,由于您确实记得关闭<td>and<tr>标记,因此它被包含在它们之外。

解析页面后,MediaWiki 在其上运行HTML Tidy。当 Tidy 看到你未关闭的表时,它会对它做两件事:

  • 它将缺少的</table>标签添加到页面的末尾。

  • 它看到表格内有一些内容,但在表格单元格之外,应该没有内容。它将该内容从表格中拉出,并将其放在表格之前

最终结果是,未封闭表格之后的页面上的所有内容最终都会在最终的、整理好的 HTML 中向上移动到它之前。确实很奇怪。

可以说,HTML Tidy应该更聪明地处理这种情况:如果它在最后一个表格单元格之后看到一个带有非表格标记的未关闭表格,它应该关闭那里的表格,而不是假设以下内容也是表格的一部分。可能值得将此作为对 Tidy 的错误/功能请求进行报告。也就是说,模板中未封闭或格式不正确的 HTML 标记还有很多其他方式可能会弄乱您的页面,因此修复这一特定情况可能不会对总体方案产生太大影响。

在您问之前,是的,在 MediaWiki 模板中拥有无与伦比的 HTML 的能力被认为是一项功能,因为它可以让您执行以下操作:

{{begin quote}}
This is some text wrapped in a fancy quote box by the surrounding templates.
{{end quote}}

无论如何,解决这个特定问题很简单:只需将缺少的内容添加</table>到您的模板中。

于 2014-11-16T01:22:40.720 回答