如何用狮身人面像制作2列

发布于 2025-01-09 07:00:22 字数 298 浏览 4 评论 0原文

我想在我的文档中创建多个列。

在全球范围内,我想做一些类似于 此主页 的事情,其中​​有 3 列:一列带有当前版本,其中包含新闻和内容更新和基础知识。

当我在谷歌上搜索有关 Sphinx 中的多列时,我发现将列表分成两列,这不是我的情况

在维基上我发现的多列的唯一内容是表格,但我认为这不适用于此处?

在使用 Sphinx 的第一个文件中这可能吗?

多谢

I want to make multiple columns on my documentation.

Globally, i would like to do something similar as this homepage, where there is 3 columns : one with current release, one with news & updates, and Basics.

When i search on google about multiple columns in Sphinx, i found about splitting a list in 2 columns which is not my case

On the wiki the only things i found with multiple columns is the table, but i don't think this can apply here ?

Is this possible in rst files using Sphinx ?

Thanks a lot

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

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

发布评论

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

评论(5

抠脚大汉 2025-01-16 07:00:22

好吧,我终于找到了:

您可以在 sphinx/rst 文件中使用 container 关键字来分隔内容

.. container:: twocol

    .. container:: leftside

        text on left column

    .. container:: rightside

        text on right column

然后在您的 .css 文件中:

div.leftside {
  width: 43%;
  padding: 0px 3px 0px 0px;
  float: left;
}

div.rightside {
  margin-left: 45%;
  /* float: right; */
}

使用此方法,您可以在容器中写入您想要的所有内容(图像,链接、文本……它将正确显示。

Ok i finally found it :

you can use container keyword in sphinx/rst files to separate things

.. container:: twocol

    .. container:: leftside

        text on left column

    .. container:: rightside

        text on right column

And then in your .css file :

div.leftside {
  width: 43%;
  padding: 0px 3px 0px 0px;
  float: left;
}

div.rightside {
  margin-left: 45%;
  /* float: right; */
}

With this method, you can write everything you want in the container (image, links, text, ... and it will be displayed properly.

瑾夏年华 2025-01-16 07:00:22

这是一个有点老的问题,但现在这个问题的一个可能更好的答案是使用 https://sphinx-panels.readthedocs.io/en/latest/

该扩展提供了您在普通休息中没有的各种组件。

This is a bit of an old question, but a potentially better answer to this question nowadays is to use https://sphinx-panels.readthedocs.io/en/latest/

That extension provides various components that you don't have in plain reST.

请帮我爱他 2025-01-16 07:00:22

一种解决方案是使用 sphinx-design 扩展,它是面板的后继者。重要的是,这不需要您配置任何 html 或 css。

One solution is to use the sphinx-design extension which is the successor to panels. Importantly, this does not require you to configure any html or css.

旧街凉风 2025-01-16 07:00:22

有几种方法可以做到这一点,因此您可以找到一个基于三列的 sphinx 主题(据我所知没有),或者作为 @Steve_Piercy 建议您可以创建自己的主题,这可能是一项艰巨的任务。但是,您可以使用选择的主题,只需调整 .rst 文件内容并覆盖您的主题即可以 3 列的方式显示内容。为此,您需要一些 HTML 和 CSS。

因此,首先您需要创建一个 test.rst ,其中的内容为 html 原始代码,如下所示:

Test
======

.. raw:: html

    <div class="row">
      <div class="column" style="background-color:#aaa;">
        <h2>Column 1</h2>
        <p>Some text..</p>
      </div>
      <div class="column" style="background-color:#bbb;">
        <h2>Column 2</h2>
        <p>Some text..</p>
      </div>
      <div class="column" style="background-color:#ccc;">
        <h2>Column 3</h2>
        <p>Some text..</p>
      </div>
    </div>

现在内容已准备就绪,我们在 _static/custom_style 下为其创建一个样式文件。 css 包含以下代码:

/* Create three equal columns that floats next to each other */
.column {
  float: left;
  width: 33.33%;
  padding: 10px;
  height: 500px;
}

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}

最后一步是将此样式添加到您的 conf.py 文件中,以便将其添加到您的主题中。因此,在您的 conf.py 中添加以下行:

def setup(app):
    app.add_stylesheet('custom_style.css')

就是这样,现在运行并测试。输出应该看起来像这样(取决于您的主题):
输入图片此处描述

There are a couple of ways to do this, so either you find a three-columns-based sphinx theme (not that I know of any) or as @Steve_Piercy suggested you can create your own theme, which will probably be quite the task. However, you can instead use a theme of choice and simply adjust your .rst file content and overwrite your theme to display your content in 3 columns fashion. To do that you need some HTML and CSS though.

So first you need to create a test.rst with your content as html raw code like the following:

Test
======

.. raw:: html

    <div class="row">
      <div class="column" style="background-color:#aaa;">
        <h2>Column 1</h2>
        <p>Some text..</p>
      </div>
      <div class="column" style="background-color:#bbb;">
        <h2>Column 2</h2>
        <p>Some text..</p>
      </div>
      <div class="column" style="background-color:#ccc;">
        <h2>Column 3</h2>
        <p>Some text..</p>
      </div>
    </div>

Now that the content is ready, we create a style file for it under _static/custom_style.css that includes the following code:

/* Create three equal columns that floats next to each other */
.column {
  float: left;
  width: 33.33%;
  padding: 10px;
  height: 500px;
}

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}

The last step is to add this style to your conf.py file in order for it to be added it to your theme. So in your conf.py add the following lines:

def setup(app):
    app.add_stylesheet('custom_style.css')

That's it, now run and test. The output should look somewhat like this (depending on your theme):
enter image description here

拥醉 2025-01-16 07:00:22

我不允许向 LudwigVonKoopa 接受的解决方案添加评论,但存在如何结束两列设置的问题。
除了已接受的解决方案之外,根据 SuperKogito 的答案,我将其添加到我的 css 文件中:


/* Clear floats after the columns */
div.after {
  content: "";
  display: table;
  clear: both;
}

这允许使用以下内容结束两列部分

.. |space| unicode:: U+0020 .. space

.. container:: twocol

    .. container:: leftside

       Left side text

    .. container:: rightside
     
       Right side text


.. container:: after

   |space|

。这不会在 html 输出中生成一行,但它会结束两列部分。

I am not allowed to add a comment to the accepted solution from LudwigVonKoopa but there is the question how to end the two column setting.
Additionally to the accepted solution and based on the answer from SuperKogito, I added this to my css file:


/* Clear floats after the columns */
div.after {
  content: "";
  display: table;
  clear: both;
}

This allows to end the two column part with

.. |space| unicode:: U+0020 .. space

.. container:: twocol

    .. container:: leftside

       Left side text

    .. container:: rightside
     
       Right side text


.. container:: after

   |space|

This does not generate a line in the html output but it ends the two column part.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文