MediaWiki我如何得到[折叠]链接不移动位置与文本

MediaWiki How do I get the [Collapse] link to NOT move position with the text?

本文关键字:链接 移动 位置 文本 折叠 何得 MediaWiki      更新时间:2023-09-26

当您点击[Expand]时,[Collapse]链接会出现,但会随着文本的长度向右移动。
我不想让[Collapse]链接向右移动,我想让它显示put。

我如何让[Collapse]链接不与文本移动位置?

{| class="mw-collapsible mw-collapsed" style="text-align:left;"<br>
! '''Header'''<br>
|-<br>
|<br>
Line1: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
Line2: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
Line3: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
Line4: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
Line5: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
|}


要阻止展开/折叠链接移动,可以在表格上设置宽度,例如:

{| class="mw-collapsible mw-collapsed"
! style="width: 50em" | '''Header'''
|-
| Line1: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
  Line2: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
  Line3: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
  Line4: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
  Line5: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
|}

(我删除了额外的<br>元素和align: left)

不幸的是,由于"展开"answers"折叠"之间的宽度差异,表头仍然会稍微移动位置。如果想要停止这种移动,可以在wiki的全局样式表Mediawiki:Common.css中添加一条语句来指定切换的宽度。检查源代码,开关位于类.mw-collapsible-toggle的元素中,因此您可以在Mediawiki:Common.css中使用如下语句指定宽度:

.mw-collapsible-toggle { width: 5em; }

您还可以将页眉向左对齐(就像您在原始示例中所做的那样),而不是集中对齐。

girlwithglasses的解决方案是正确的。但是,如果[collapse]链接仍然在移动,那是因为内容(由于间距而放在<pre>标签之间)迫使表格的宽度超过50em。可以通过显式设置单元格的max-width:

来防止这种情况。
{| class="mw-collapsible mw-collapsed"
! style="width: 50em" | '''Header'''
|-
| style="max-width: 50em" |
  Line1: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
  Line2: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
  Line3: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
  Line4: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
  Line5: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
|}

…或者,当然,通过删除前导空格:

{| class="mw-collapsible mw-collapsed"
! style="width: 50em" | '''Header'''
|-
| Line1: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
Line2: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
Line3: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
Line4: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
Line5: A long line of text that is used to test the position of the [Collapse] link in my document.<br>
|}