如何更改 JupyterLab 中单元格的样式/宽度?

Aki*_*ira 3 html css ipython python-3.x jupyter-lab

我试过

from IPython.core.display import display, HTML
display(HTML("<style>.container { width:60% !important; }</style>"))
Run Code Online (Sandbox Code Playgroud)

从这个答案来看。我也尝试过

%%html
<style>.container { width:60% !important; }</style>
Run Code Online (Sandbox Code Playgroud)

但它们不起作用。

在此输入图像描述

kra*_*ski 6

类的名称在 JupyterLab 中进行了重新设计,现在更容易理解且更可预测。对 JupyterLab 使用以下选择器:

  • .jp-Cell更改所有单元格的宽度
  • .jp-Cell.jp-CodeCell使用代码仅更改单元格的宽度
  • .jp-Cell.jp-MarkdownCell更改 Markdown 单元格的宽度
  • .jp-Cell.jp-Editor仅更改编辑器的宽度
  • .jp-OutputArea-output改变单元输出的 with

例如,要使用 IPython 减小单元格的宽度,您可以使用:

from IPython.core.display import display, HTML
display(HTML("<style>.jp-Cell { width: 60% !important; }</style>"))
Run Code Online (Sandbox Code Playgroud)

您可以使用DOM 检查器(当今所有浏览器都提供的工具)(请参阅此处的说明)来检查您想要修改的特定元素的类名。