Html 用 colspan="2" 连接的表格数据的中心文本 .css " Select td with attribute colspan="2" "

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25594610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:36:56  来源:igfitidea点击:

center text of table data connected with colspan="2" with .css " Select td with attribute colspan="2" "

htmlcsswordpresshtml-table

提问by Viktor Carlson

Hi I have a table where certain columns in a row are connected with the colspan="2"attribute.

嗨,我有一个表格,其中一行中的某些列与colspan="2"属性相连。

In the moment it looks like this:

此刻它看起来像这样:

enter image description here

在此处输入图片说明

I want that the text of the connected columns in a row is centered, but only the text in the connected columns

我希望一行中连接列的文本居中,但只有连接列中的文本

The table data of this row (unlimited ) has the following code

该行的表数据(无限制)有如下代码

<tr class="row-4 even">    
<td colspan="2" class="column-3 footable-last-column" style="display: table-cell;">unlimited</td>
</tr>

I can not change the code of the table because it is automatically created by the Wordpress plugin tablepress

我无法更改表格的代码,因为它是由 Wordpress 插件自动创建的 tablepress

What I can do is to add a custom .css file.

我能做的是添加一个自定义的 .css 文件。

My Question is, if it is possible to select only the table data with the attribute colspan="2"with .css, so that I can do { text-align: center }only for table data with the attribute colspan="2"

我的问题是,是否可以仅选择colspan="2"具有 .css属性的表数据 ,以便我{ text-align: center }只能选择具有该属性的表数据colspan="2"

回答by HymanW

The CSS selector [attribute="value"]is what you want, so you should add

CSS 选择器[attribute="value"]就是你想要的,所以你应该添加

td[colspan="2"] {
    text-align: center;
}

to center the cell that spans two columns.

将跨越两列的单元格居中。

If you want to center cells that span any number of columns, you can use

如果要将跨越任意数量列的单元格居中,可以使用

td[colspan]:not([colspan="1"]) {
    text-align: center;
}

to select all cells that have a colspanattribute set to a value other than 1.

选择colspan属性设置为 以外的值的所有单元格1

回答by Dut A.

This should do the trick if you are applying the CSS inline:

如果您正在应用 CSS 内联,这应该可以解决问题:

<td colspan="2" style="text-align:center;">unlimited</td>