如何更改 reStructuredText 中表格单元格的背景颜色?

发布于 2024-12-02 06:33:10 字数 852 浏览 1 评论 0原文

以下如何在带有重构文本 (rst2html.py) 的文本中使用颜色或如何插入没有空行的 HTML 标记? 我能够在表格中设置文本的背景,如下所示

.. role:: gbg

.. raw:: html

   <style>
      .gbg {background-color:#00ff00;} 
   </style>

+-------+----------------+-------+---------+-------+---------+
| UTC+1 | (d-s)          | UTC-6 | (zo)    | UTC-7 | (za)    |
+=======+================+=======+=========+=======+=========+
| 15:00 | :gbg:`avail`   |  8:00 |         |  7:00 |         |
+-------+                +-------+---------+-------+         +
| 15:30 |                |  8:30 |         |  7:30 |         |
+-------+----------------+-------+---------+-------+---------+

: “avail”一词在字母后面有绿色背景,但是如何使整个单元格具有彩色背景,而不仅仅是这些字母后面的部分?

Following How to use color in text with ReStructured Text (rst2html.py) or how to insert HTML tags without blank lines? I was able to set the background of the text within a table, like this:

.. role:: gbg

.. raw:: html

   <style>
      .gbg {background-color:#00ff00;} 
   </style>

+-------+----------------+-------+---------+-------+---------+
| UTC+1 | (d-s)          | UTC-6 | (zo)    | UTC-7 | (za)    |
+=======+================+=======+=========+=======+=========+
| 15:00 | :gbg:`avail`   |  8:00 |         |  7:00 |         |
+-------+                +-------+---------+-------+         +
| 15:30 |                |  8:30 |         |  7:30 |         |
+-------+----------------+-------+---------+-------+---------+

That results in the word "avail" having a green background behind the letters, but how can I make the entire cell have a colored background instead of just the part of it behind those letters?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白龙吟 2024-12-09 06:33:10

用 javascript 拼凑它:

.. role:: gbg

.. raw:: html

   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
   <script>
     $(document).ready(function() {
       $('.gbg').parent().addClass('gbg-parent');
     });
   </script>
   <style>
      .gbg-parent {background-color:#00ff00;}
   </style>

+-------+----------------+-------+---------+-------+---------+
| UTC+1 | (d-s)          | UTC-6 | (zo)    | UTC-7 | (za)    |
+=======+================+=======+=========+=======+=========+
| 15:00 | :gbg:`avail`   |  8:00 |         |  7:00 |         |
+-------+                +-------+---------+-------+         +
| 15:30 |                |  8:30 |         |  7:30 |         |
+-------+----------------+-------+---------+-------+---------+

Kludge it with javascript:

.. role:: gbg

.. raw:: html

   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
   <script>
     $(document).ready(function() {
       $('.gbg').parent().addClass('gbg-parent');
     });
   </script>
   <style>
      .gbg-parent {background-color:#00ff00;}
   </style>

+-------+----------------+-------+---------+-------+---------+
| UTC+1 | (d-s)          | UTC-6 | (zo)    | UTC-7 | (za)    |
+=======+================+=======+=========+=======+=========+
| 15:00 | :gbg:`avail`   |  8:00 |         |  7:00 |         |
+-------+                +-------+---------+-------+         +
| 15:30 |                |  8:30 |         |  7:30 |         |
+-------+----------------+-------+---------+-------+---------+
千寻… 2024-12-09 06:33:10

休息:

.. table::
   :class: rows

   +-------+----------------+-------+---------+-------+---------+
   | UTC+1 | (d-s)          | UTC-6 | (zo)    | UTC-7 | (za)    |
   +=======+================+=======+=========+=======+=========+
   | 15:00 | avail          |  8:00 |         |  7:00 |         |
   +-------+                +-------+---------+-------+         +
   | 15:30 |                |  8:30 |         |  7:30 |         |
   +-------+----------------+-------+---------+-------+---------+

CSS:

table.rows th {
    background-color: #ede;
    border-style: solid solid solid solid;
    border-width: 0px 0px 0px 0px;
    border-color: #AAAAAA;
    text-align: center;
}
table.rows td {
    border-style: solid solid solid solid;
    border-width: 0px 0px 0px 0px;
    border-color: #AAAAAA;
}

table.rows tr {
    border-style: solid solid solid solid;
    border-width: 0px 0px 0px 0px;
    border-color: #AAAAAA;
}

table.rows tr:nth-child(even) {
    background-color: #F3F3FF;
}
table.rows tr:nth-child(odd) {
    background-color: #FFFFEE;
}

REsT:

.. table::
   :class: rows

   +-------+----------------+-------+---------+-------+---------+
   | UTC+1 | (d-s)          | UTC-6 | (zo)    | UTC-7 | (za)    |
   +=======+================+=======+=========+=======+=========+
   | 15:00 | avail          |  8:00 |         |  7:00 |         |
   +-------+                +-------+---------+-------+         +
   | 15:30 |                |  8:30 |         |  7:30 |         |
   +-------+----------------+-------+---------+-------+---------+

CSS:

table.rows th {
    background-color: #ede;
    border-style: solid solid solid solid;
    border-width: 0px 0px 0px 0px;
    border-color: #AAAAAA;
    text-align: center;
}
table.rows td {
    border-style: solid solid solid solid;
    border-width: 0px 0px 0px 0px;
    border-color: #AAAAAA;
}

table.rows tr {
    border-style: solid solid solid solid;
    border-width: 0px 0px 0px 0px;
    border-color: #AAAAAA;
}

table.rows tr:nth-child(even) {
    background-color: #F3F3FF;
}
table.rows tr:nth-child(odd) {
    background-color: #FFFFEE;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文