Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css Mediawiki表:";“有效地”;对不同的柱应用不同的对齐方式_Css_Html Table_Mediawiki - Fatal编程技术网

Css Mediawiki表:";“有效地”;对不同的柱应用不同的对齐方式

Css Mediawiki表:";“有效地”;对不同的柱应用不同的对齐方式,css,html-table,mediawiki,Css,Html Table,Mediawiki,如何有效地将某些列居中对齐,而将其他列左对齐 我想做这样的事 ------------------------- | A |B | ------------------------- | C |D | ------------------------- 此代码使所有列居中 {| class="wikitable" style="text-align: center;" |- ! Header 1 ! Header 2

如何有效地将某些列居中对齐,而将其他列左对齐

我想做这样的事

-------------------------
|     A      |B         |
-------------------------
|     C      |D         |
-------------------------    
此代码使所有列居中

{| class="wikitable" style="text-align: center;"
|-
! Header 1
! Header 2
|-
| A
| B
|-
| C
| D
|}
我知道下面的代码符合我的要求

{| class="wikitable"
|-
! Header 1
! Header 2
|-
| style="text-align: center;" | A
| B
|-
| style="text-align: center;" | C
| D
|}
但是因为我需要做一张很长的桌子,这很乏味


是否有任何代码只使用一行非常简单的代码将第一列居中对齐?

除非您在
LocalSettings.php
中禁用它,否则您可以使用页面
MediaWiki:Common.css
向所有页面添加额外的样式表。只需使用简单的CSS就可以完成您需要的操作。例如:

.myTableClass td {
    text-align: left;
}

.myTableClass td:first-child {
    text-align: center;
}
…然后将该类添加到表中

{| class="wikitable myTableClass"
|-
| A
| B
|-
| C
| D
|}

公认的答案虽然正确,但一般来说实现起来可能很乏味,因为您需要为所需的列位置和文本对齐的每个组合创建一个独特的CSS类

一次性的另一种方法是将CSS直接嵌入wiki页面。在仅由受信任用户编辑的Wiki上,您可以启用。在其他情况下,可以使用扩展名,例如。如果有多个表,可以使用
#id
选择器将样式设置限制为每个表

<html>   <!-- assumes $wgRawHtml = true; safer alternatives exist -->
    <style>
        table#accounts tr td:nth-child(3),
        table#accounts tr td:nth-child(4) 
        { 
            text-align: right; 
        }
    </style>
</html>
{| class="wikitable" id="accounts"
! Account Number !! Account Name !! Source Balance !! Target Balance
|-
| 1234 || UK Savings     ||    402.00 ||    323.21
|-
| 5432 || Car Fund       || 12,943.00 || 23,433.21
|-
| 6789 || Other Expenses ||      4.21 ||      6.21
|}
然后,在wiki页面中,您可以简单地引用CSS类:

{| class="wikitable col-3-right col-4-right"
! Account Number !! Account Name !! Source Balance !! Target Balance
|-
| 1234 || UK Savings     ||    402.00 ||    323.21
|-
| 5432 || Car Fund       || 12,943.00 || 23,433.21
|-
| 6789 || Other Expenses ||      4.21 ||      6.21
|}

这种方法的另一个优点是,您不需要启用
$wgRawHtml
或安装扩展。

对于我的情况,类应该是什么(一些列居中对齐,其他列左对齐)?上面的示例用于使每行的第一列居中对齐,其余列左对齐!
{| class="wikitable col-3-right col-4-right"
! Account Number !! Account Name !! Source Balance !! Target Balance
|-
| 1234 || UK Savings     ||    402.00 ||    323.21
|-
| 5432 || Car Fund       || 12,943.00 || 23,433.21
|-
| 6789 || Other Expenses ||      4.21 ||      6.21
|}