如何在浏览器中消除Jupyter / ipython笔记本周围的灰色边框?

时间:2017-06-01 05:01:57

标签: python html css jupyter-notebook ipython-notebook

我在this thread中读到了如何更改Jupyter笔记本的单元格宽度(我使用second answer动态执行此操作)。此方法消除了左右灰色边框。

但是,这仍然会在文档的顶部和底部处留下灰色边框。我怎样才能将它移除,以便细胞躺在干净的石板上?

4 个答案:

答案 0 :(得分:7)

更新2019/02/18 : 我建议安装jupyterthemes,而不是执行以下操作。这些笔记本主题非常棒,漂亮且易于使用,并且消除了灰色边框。

原帖

所以在使用" Inspect Element"在笔记本上学习CSS的iota,似乎以下工作

from IPython.core.display import display, HTML
display(HTML("<style>"
    + "#notebook { padding-top:0px !important; } " 
    + ".container { width:100% !important; } "
    + ".end_space { min-height:0px !important; } "
    + "</style>"))

其中顶行删除顶部的灰色边距,中间线删除侧边距,底部线条删除底部的灰色边距。 <style></style>之间的内容当然也可以添加到this thread之后的custom.css中的~/.jupyter/custom/文件中;我的文件包含行

/* Modifications to notebook format  */
#notebook { padding-top:0px !important; } /* eliminate top gray */
.container { width:100% !important; } /* eliminate side gray */
.end_space { min-height:0px !important; } /* eliminate bottom gray */

答案 1 :(得分:0)

我会将以下内容添加到我的CSS中

*{margin:0;
  padding:0;
}

html, body, .container{
   margin:0!important;
   padding:0!important;
}

这应该摆脱顶部和底部以及侧面的额外空间。如果它是您所指的边界线,则可以将border:0;添加到html,body css

看到评论后更新:

从你给定的解决方案中,你也可以对高度(height:100%;!important)做同样的事情,但根据我的经验设置100%到高度属性不如宽度有效(因为高度更动态)尝试html /身体的第一件事。

带有html / body属性的内联样式示例:

from IPython.core.display import display, HTML
display(HTML("<style> *{margin:0; padding:0;} html, body, .container{margin:0;!important padding:0;!important} .container { width:100% !important;}</style>"))

答案 2 :(得分:0)

实验了一些建议并部署了萤火虫,这是我为最大程度地利用工作空间而进行的更改。使用df = df.drop(df[(df.property.startswith('propB')) & (df.value < 4)].index) css属性对我而言不起作用,因为我偶尔使用width插件并设置table of contents会使事情变得混乱。

笔记本css替代

将以下CSS添加到width

~/.jupyter/custom/custom.css

当然,如果该文件中已有内容,则需要将以前的设置与此文件合并。

如果我尚未安装/* Modifications to notebook layout to maximize working space */ /* maximize working space */ #notebook { padding: 5px 0 5px 0 !important; } /* eliminate most of bottom gray */ .end_space { min-height: 5px !important; } /* reduce white padding on the outside of the notebook */ #notebook-container { padding: 5px; } /* less padding in sub-cells on the left with In[] */ .run_this_cell { padding-left: 0px; padding-right: 0px; } ,则可能需要重新启动jupyter。

最大程度地减少目录插件的影响。

在撰写本文时,此插件在笔记本电脑主体的两侧强制设置了较深的灰色边距。我要求使margin变量可配置。在实施之前(如果有的话),我做到了:

custom.css

其中cd ~/.local/share/jupyter/nbextensions patch -p0 < margin-width.patch 包含:

margin-width.patch

您无需重新启动jupyter即可使此更改生效。

结果

现在我可以很好地利用所有可用空间,而又不会太紧:

Snapshot of the notebook after removing wasted grey/white space

答案 3 :(得分:0)

我来到这里是因为我想在选中时删除单元格边框。我希望这对其他人有用。

#pragma once

#include <exception>
#include <cstdint>
#include <cerrno>

class DynamicLibrary
{
public:
    DynamicLibrary(const char *fileName);
    ~DynamicLibrary();

    void *getFunctionPtr(const char *name) const;

    DynamicLibrary(const DynamicLibrary &) = delete;
    DynamicLibrary & operator = (const DynamicLibrary &other) = delete;

private:
    void *libHandle;
};

struct ANativeWindowBuffer;

namespace android
{
    class GraphicBuffer;

    // include/system/window.h
    struct android_native_base_t
    {
        uint32_t magic;
        uint32_t version;
        void* reserved[4];
        void (*incRef)(struct android_native_base_t* base);
        void (*decRef)(struct android_native_base_t* base);
    };

    // include/ui/android_native_buffer.h
    struct android_native_buffer_t
    {
        struct android_native_base_t common;
        int32_t width;
        int32_t height;
        int32_t stride;
        int32_t format;
        int32_t usage;
        // ...
    };
}

// utils/Errors.h
enum status_t
{ /*ommited, look at the gist */        };

// ui/PixelFormat.h, system/graphics.h
enum PixelFormat
{ /*ommited, look at the gist */        };

// ui/GraphicBuffer.h
{ /*ommited, look at the gist */        };

class GraphicBuffer
{
public:
    // ui/GraphicBuffer.h, hardware/gralloc.h

    GraphicBuffer(uint32_t width, uint32_t height, PixelFormat format, uint32_t usage);
    ~GraphicBuffer();

    status_t lock(uint32_t usage, void** vaddr);
    status_t unlock();
    ANativeWindowBuffer *getNativeBuffer() const;
    uint32_t getStride() const;

private:
    DynamicLibrary library;
    GraphicBufferFunctions functions;
    android::GraphicBuffer *impl = nullptr;
};
#include "GraphicBuffer.h"