MediaWiki信息框删空行后出空白行及缩进问题求助
问题解决方法
一、顶部空白行问题
你的代码里有两个核心错误导致该问题:
- CSS语法错误:
.infobox td:nth-child(1)的闭合大括号缺失,直接嵌套了下一个选择器,导致后续tr:first-child规则失效,同时破坏了整个CSS的解析逻辑。 - MediaWiki表格结构错误:混用HTML的
<tr>标签和MediaWiki原生表格语法({|),且表格未用|}闭合,解析时会生成多余空白节点。
修正后的CSS代码
{{#css: .infobox { width: 270px; color: #000000; line-height: 1.3; border-collapse: collapse; /* 可选:消除表格默认间距 */ } .infobox td:nth-child(2) { text-align: left; padding-left: 8px; /* 同时解决缩进问题 */ } .infobox td:nth-child(1) { text-align: left; font-weight: bold; width: 30%; max-width: 100px; } /* 补上缺失的闭合大括号 */ .infobox tr:first-child { display: none; } }}
修正后的MediaWiki表格代码
改用MediaWiki原生表格语法,避免混用标签导致解析异常:
<div style="border: 1px solid #aaa; background-color: #F8F9FA; padding: 5px; text-align: center; font-size: 90%; float: right; margin: 0 0 10px 10px;"> {| class="infobox" ! colspan="2" style="background-color: #99BADD; font-size: 120%; vertical-align: top;" | {{{name}}} |- | colspan="2" style="text-align:center;" | [[File:{{{image}}}|alt={{{alt}}}]] <!-- 用MediaWiki文件语法更规范 --> |- ! colspan="2" style="background-color: #CCBBEE;" | {{{title}}} {{#if: {{{birth|}}} | {{!}}- {{!}} Born {{!}} {{{birth}}}<br>{{{birth-place}}} }} {{#if: {{{death|}}} | {{!}}- {{!}} Died {{!}} {{{death}}}<br>{{{death-place}}} }} {{#if: {{{house|}}} | {{!}}- {{!}} House {{!}} {{{house}}} }} {{#if: {{{spouse|}}} | {{!}}- {{!}} Spouse(s) {{!}} {{{spouse}}} }} {{#if: {{{issue|}}} | {{!}}- {{!}} Issue {{!}} {{{issue}}} }} {{#if: {{{father|}}} | {{!}}- {{!}} Father {{!}} {{{father}}} }} {{#if: {{{mother|}}} | {{!}}- {{!}} Mother {{!}} {{{mother}}} }} |} <!-- 补上表格闭合标签 --> </div>
用{{!}}代替竖线、|-分隔行,可避免ParserFunctions的if语句产生多余换行空白,同时闭合表格结构,彻底解决顶部空白问题。
二、Spouse(s)缩进问题
在修正后的CSS中,.infobox td:nth-child(2)已添加padding-left: 8px;(数值可根据需求调整),能让右侧内容产生缩进,和左侧标题区分开。如果仍无效果,可临时添加!important排查是否被全局样式覆盖(不推荐长期使用):
.infobox td:nth-child(2) { text-align: left; padding-left: 8px !important; }
内容的提问来源于stack exchange,提问作者bradeblo
相关产品推荐
相关产品推荐

