【问题标题】:Removing borders from a table in sphinx documentation从 sphinx 文档中的表格中删除边框
【发布时间】:2020-10-18 22:38:10
【问题描述】:

我在 readthedocs 上托管的第一个文件中有一个表格,我想从中删除边框。麻烦的是,我在 CSS 文件中尝试的任何方法似乎都不起作用。我已经查看了其他几个解决方案,但还没有成功。

这是 rst 中表格的(缩短的)示例(请注意,我已拆分最后三行中的列以创建嵌套效果,不确定这是否会导致任何并发症)。

+------------------+-----------------------------+------------+-------------------------------------+
|  Parameter       |  Description                |  Type      |    Notes                            |
+==================+=============================+============+=====================================+
| patrolID         | ID of the submitted patrol. |  int       | Assigned automatically by the patrol|
|                  |                             |            | app.                                |
+------------------+-----------------------------+------------+-------------------------------------+
| date             | Date the patrol             |  string    | Format is YYYY-MM-DD.               |
|                  | occurred.                   |            |                                     |
+------------------+-----------------------------+------------+-------------------------------------+
| userID           | The alias of the individual |  string    | Matches the user’s Vanguard email   |
|                  | who submitted the patrol.   |            | alias (For example, MScott).        |
+------------------+-----------------------------+------------+-------------------------------------+
| patrolStart      | Time the patrol started.    |  int       | Format is 24-hour (Ex: 0700         |
|                  |                             |            | or 1400).                           |
+------------------+-----------------------------+------------+-------------------------------------+ 
| patrolEnd        | Time the patrol ended.      |  int       | Format is 24-hour (Ex: 0700         |
|                  |                             |            | or 1400).                           |
+------------------+-----------------------------+------------+-------------------------------------+
|perimeterFence    |  Patrol area.               |  object    |                                     |
+----+-------------+-----------------------------+------------+-------------------------------------+
|    |time         | Time the area was patrolled.|  int       | Format is 24-hour (Ex: 0700         |
|    |             |                             |            | or 1400).                           |
+----+-------------+-----------------------------+------------+-------------------------------------+
|    |incident     | Indicates whether anything  |  boolean   | Default value is false.             |
|    |             | unusual was encountered     |            |                                     |
|    |             | during the patrol.          |            |                                     |
+----+-------------+-----------------------------+------------+-------------------------------------+
|    |details      | Summary of area patrol.     |  string    | When incident is false, the default |
|    |             |                             |            | value will be "Nothing to report."  |
+----+-------------+-----------------------------+------------+-------------------------------------+

表格在 readthedocs 上的外观截图:

表格的 HTML 代码(我无法使用 RTD 更改类名或元素,所以所见即所得)

<div class="section" id="submit-a-patrol">
<h2><a class="toc-backref" href="#id1">Submit a patrol</a><a class="headerlink" href="#submit-a-patrol" title="Permalink to this headline">¶</a></h2>
<p>URL: POST <a class="reference external" href="https://api.vanguard.com/patrol">https://api.vanguard.com/patrol</a>/{PatrolID}</p>
<p>Adds a patrol report. A successful response requires all listed parameters be included with appropriate values.</p>
<table border="1" class="docutils">
<colgroup>
<col width="4%" />
<col width="14%" />
<col width="31%" />
<col width="13%" />
<col width="39%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head" colspan="2">Parameter</th>
<th class="head">Description</th>
<th class="head">Type</th>
<th class="head">Notes</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td colspan="2">patrolID</td>
<td>ID of the submitted patrol.</td>
<td>int</td>
<td>Assigned automatically by the patrol
app.</td>
</tr>
<tr class="row-odd"><td colspan="2">date</td>
<td>Date the patrol
occurred.</td>
<td>string</td>
<td>Format is YYYY-MM-DD.</td>
</tr>
<tr class="row-even"><td colspan="2">userID</td>
<td>The alias of the individual
who submitted the patrol.</td>
<td>string</td>
<td>Matches the user’s Vanguard email
alias (For example, MScott).</td>
</tr>
<tr class="row-odd"><td colspan="2">patrolStart</td>
<td>Time the patrol started.</td>
<td>int</td>
<td>Format is 24-hour (Ex: 0700
or 1400).</td>
</tr>
<tr class="row-even"><td colspan="2">patrolEnd</td>
<td>Time the patrol ended.</td>
<td>int</td>
<td>Format is 24-hour (Ex: 0700
or 1400).</td>
</tr>
<tr class="row-odd"><td colspan="2">perimeterFence</td>
<td>Patrol area.</td>
<td>object</td>
<td>&#160;</td>
</tr>
<tr class="row-even"><td>&#160;</td>
<td>time</td>
<td>Time the area was patrolled.</td>
<td>int</td>
<td>Format is 24-hour (Ex: 0700
or 1400).</td>
</tr>
<tr class="row-odd"><td>&#160;</td>
<td>incident</td>
<td>Indicates whether anything
unusual was encountered
during the patrol.</td>
<td>boolean</td>
<td>Default value is false.</td>
</tr>
<tr class="row-even"><td>&#160;</td>
<td>details</td>
<td>Summary of area patrol.</td>
<td>string</td>
<td>When incident is false, the default
value will be “Nothing to report.”</td>
</tr>
<tr class="row-odd"><td colspan="2">facilityExterior</td>
<td>Patrol area.</td>
<td>object</td>
<td>&#160;</td>
</tr>
<tr class="row-even"><td>&#160;</td>
<td>time</td>
<td>Time the area was patrolled.</td>
<td>int</td>
<td>Format is 24-hour (Ex: 0700
or 1400).</td>
</tr>
<tr class="row-odd"><td>&#160;</td>
<td>incident</td>
<td>Indicates whether anything
unusual was encountered
during the patrol.</td>
<td>boolean</td>
<td>Default value is false.</td>
</tr>
<tr class="row-even"><td>&#160;</td>
<td>details</td>
<td>Summary of area patrol.</td>
<td>string</td>
<td>When incident is false, the default
value will be “Nothing to report.”</td>
</tr>
<tr class="row-odd"><td colspan="2">facilityInterior</td>
<td>Patrol area.</td>
<td>object</td>
<td>&#160;</td>
</tr>
<tr class="row-even"><td>&#160;</td>
<td>time</td>
<td>Time the area was patrolled.</td>
<td>int</td>
<td>Format is 24-hour (Ex: 0700
or 1400).</td>
</tr>
<tr class="row-odd"><td>&#160;</td>
<td>incident</td>
<td>Indicates whether anything
unusual was encountered
during the patrol.</td>
<td>boolean</td>
<td>Default value is false.</td>
</tr>
<tr class="row-even"><td>&#160;</td>
<td>details</td>
<td>Summary of area patrol.</td>
<td>string</td>
<td>When incident is false, the default
value will be “Nothing to report.”</td>
</tr>
</tbody>
</table>
<p><strong>Responses</strong></p>
<table border="1" class="docutils">
<colgroup>
<col width="21%" />
<col width="79%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Code</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>200</td>
<td>Successful operation.</td>
</tr>
</tbody>
</table>

终于有了我目前拥有的 CSS。

div.section table, td
{
  white-space: normal !important;  
}

div.section tbody, tr, td
{
  border: none; 
}

div.section thead, th
{
  color: #FFFFFF;
  background-color: #4472C4;    
}

div.section tr.row-odd
{
  background-color: #D9E2F3;  
}

我尝试过定位 table、tbody、.docutils 和其他排列,但无法做任何事情来影响边框,尽管所有其他 CSS 条目都做了它们应该做的事情。欢迎任何想法。

【问题讨论】:

    标签: html css restructuredtext read-the-docs


    【解决方案1】:

    我无法在this JSFiddle 中复制该问题。

    我怀疑你没有added your custom CSS file to conf.py

    conf.py

    ​​>
    # These folders are copied to the documentation's HTML output
    html_static_path = ['_static']
    
    # These paths are either relative to html_static_path
    # or fully qualified paths (eg. https://...)
    html_css_files = [
        'css/custom.css',
    ]
    
    div.section table, td
    {
      white-space: normal !important;  
    }
    
    div.section tbody, tr, td
    {
    //  border: none; 
    }
    
    div.section thead, th
    {
      color: #FFFFFF;
      background-color: #4472C4;    
    }
    
    div.section tr.row-odd
    {
      background-color: #D9E2F3;  
    }
    
    <div class="section" id="submit-a-patrol">
    <h2><a class="toc-backref" href="#id1">Submit a patrol</a><a class="headerlink" href="#submit-a-patrol" title="Permalink to this headline">¶</a></h2>
    <p>URL: POST <a class="reference external" href="https://api.vanguard.com/patrol">https://api.vanguard.com/patrol</a>/{PatrolID}</p>
    <p>Adds a patrol report. A successful response requires all listed parameters be included with appropriate values.</p>
    <table border="1" class="docutils">
    <colgroup>
    <col width="4%" />
    <col width="14%" />
    <col width="31%" />
    <col width="13%" />
    <col width="39%" />
    </colgroup>
    <thead valign="bottom">
    <tr class="row-odd"><th class="head" colspan="2">Parameter</th>
    <th class="head">Description</th>
    <th class="head">Type</th>
    <th class="head">Notes</th>
    </tr>
    </thead>
    <tbody valign="top">
    <tr class="row-even"><td colspan="2">patrolID</td>
    <td>ID of the submitted patrol.</td>
    <td>int</td>
    <td>Assigned automatically by the patrol
    app.</td>
    </tr>
    <tr class="row-odd"><td colspan="2">date</td>
    <td>Date the patrol
    occurred.</td>
    <td>string</td>
    <td>Format is YYYY-MM-DD.</td>
    </tr>
    <tr class="row-even"><td colspan="2">userID</td>
    <td>The alias of the individual
    who submitted the patrol.</td>
    <td>string</td>
    <td>Matches the user’s Vanguard email
    alias (For example, MScott).</td>
    </tr>
    <tr class="row-odd"><td colspan="2">patrolStart</td>
    <td>Time the patrol started.</td>
    <td>int</td>
    <td>Format is 24-hour (Ex: 0700
    or 1400).</td>
    </tr>
    <tr class="row-even"><td colspan="2">patrolEnd</td>
    <td>Time the patrol ended.</td>
    <td>int</td>
    <td>Format is 24-hour (Ex: 0700
    or 1400).</td>
    </tr>
    <tr class="row-odd"><td colspan="2">perimeterFence</td>
    <td>Patrol area.</td>
    <td>object</td>
    <td>&#160;</td>
    </tr>
    <tr class="row-even"><td>&#160;</td>
    <td>time</td>
    <td>Time the area was patrolled.</td>
    <td>int</td>
    <td>Format is 24-hour (Ex: 0700
    or 1400).</td>
    </tr>
    <tr class="row-odd"><td>&#160;</td>
    <td>incident</td>
    <td>Indicates whether anything
    unusual was encountered
    during the patrol.</td>
    <td>boolean</td>
    <td>Default value is false.</td>
    </tr>
    <tr class="row-even"><td>&#160;</td>
    <td>details</td>
    <td>Summary of area patrol.</td>
    <td>string</td>
    <td>When incident is false, the default
    value will be “Nothing to report.”</td>
    </tr>
    <tr class="row-odd"><td colspan="2">facilityExterior</td>
    <td>Patrol area.</td>
    <td>object</td>
    <td>&#160;</td>
    </tr>
    <tr class="row-even"><td>&#160;</td>
    <td>time</td>
    <td>Time the area was patrolled.</td>
    <td>int</td>
    <td>Format is 24-hour (Ex: 0700
    or 1400).</td>
    </tr>
    <tr class="row-odd"><td>&#160;</td>
    <td>incident</td>
    <td>Indicates whether anything
    unusual was encountered
    during the patrol.</td>
    <td>boolean</td>
    <td>Default value is false.</td>
    </tr>
    <tr class="row-even"><td>&#160;</td>
    <td>details</td>
    <td>Summary of area patrol.</td>
    <td>string</td>
    <td>When incident is false, the default
    value will be “Nothing to report.”</td>
    </tr>
    <tr class="row-odd"><td colspan="2">facilityInterior</td>
    <td>Patrol area.</td>
    <td>object</td>
    <td>&#160;</td>
    </tr>
    <tr class="row-even"><td>&#160;</td>
    <td>time</td>
    <td>Time the area was patrolled.</td>
    <td>int</td>
    <td>Format is 24-hour (Ex: 0700
    or 1400).</td>
    </tr>
    <tr class="row-odd"><td>&#160;</td>
    <td>incident</td>
    <td>Indicates whether anything
    unusual was encountered
    during the patrol.</td>
    <td>boolean</td>
    <td>Default value is false.</td>
    </tr>
    <tr class="row-even"><td>&#160;</td>
    <td>details</td>
    <td>Summary of area patrol.</td>
    <td>string</td>
    <td>When incident is false, the default
    value will be “Nothing to report.”</td>
    </tr>
    </tbody>
    </table>
    <p><strong>Responses</strong></p>
    <table border="1" class="docutils">
    <colgroup>
    <col width="21%" />
    <col width="79%" />
    </colgroup>
    <thead valign="bottom">
    <tr class="row-odd"><th class="head">Code</th>
    <th class="head">Description</th>
    </tr>
    </thead>
    <tbody valign="top">
    <tr class="row-even"><td>200</td>
    <td>Successful operation.</td>
    </tr>
    </tbody>
    </table>
    

    【讨论】:

    • 我的 conf.py 文件看起来和那个一模一样,加上了def setup(app): app.add_stylesheet('css/custom.css')。 css文件的完整路径是doc/_static/css/custom.css
    • HTML 中的路径是否与您的conf.py 中的路径匹配? CSS 会在浏览器中加载吗?
    • HTML 中有&lt;link rel="stylesheet" href="_static/css/custom.css" type="text/css" /&gt;,由于某种原因,它被列出了两次。 CSS 的其他部分会加载,例如表格的阴影和标题行的文本颜色。
    • 使用您的网络浏览器的检查器功能查看应用于检查元素的样式。听起来您的样式被另一个样式表中的另一种样式覆盖。您可以在样式属性之后使用!important 来防止以后被覆盖。否则,请编辑您的问题以包含完整的 HTML 和静态资产的完全限定 URL,以便我们提供进一步的帮助。
    猜你喜欢
    • 2019-04-10
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    • 2018-04-29
    相关资源
    最近更新 更多