在 Sphinx 中如何设置 CSV 表的样式?

问题描述 投票:0回答:1

我在 Sphinx 中有一个简单的

csv-table
指令,我想对其进行样式设置:

Sphinx CSV-Table Styling
------------------------

.. csv-table:: Simple Example
   :header: a, b, c, d
   :widths: 5, 5, 5, 5

   1, 2, 3, 4
   5, 6, 7, 8
   9, 10, 11, 12
   13, 14, 15, 16

我想设计以下样式:

  • 更改标题背景颜色。
  • 更改每隔一行的背景。
  • 更改单个列的背景。
  • 更改单个项目的文本颜色。
python css sphinx
1个回答
0
投票

以下是我的解决方案:

.. raw:: html

   <style> 
    table.table1 th {background-color: lightgray}
    table.table1 tr:nth-child(even) { background-color: yellow}
    table.table1 td:nth-child(3) {background-color: orange}
    table.table1 tr:nth-child(1) td:nth-child(2) {background-color: lightblue}
    .red {color: red}
   </style>


Sphinx CSV-Table Styling
------------------------

.. csv-table:: Simple Example
   :header: a, b, c, d
   :widths: 5, 5, 5, 5
   :class: table1

   1, 2, 3, 4
   5, 6, 7, 8
   :red:`9`, 10, 11, 12
   13, 14, 15, 16

一些注意事项:

  • 要处理表格、标题、行、列和单个单元格背景,关键是在
    :class:
    指令中设置
    csv-table
    并创建适当的 CSS 选择器。
  • 要处理表中的文本,关键是要意识到您可以将 Sphinx 角色 (
    :red:
    ) 应用于各个文本位,并在具有相应名称的 CSS 类中设置样式 (
    .red
    )。
© www.soinside.com 2019 - 2024. All rights reserved.