简体   繁体   English

在IPython Notebook中对齐文本框小部件

[英]Aligning TextBox Widgets in IPython Notebooks

I am trying to make an IPython notebook more aesthetic by aligning input fields. 我正在尝试通过对齐输入字段来使IPython Notebook更美观。 These fields have some descriptors attached to them, and a few go over the minimum character limit. 这些字段附有一些描述符,有一些超出了最小字符限制。

I would like the text input boxes to be aligned such that the left side all align vertically. 我希望文本输入框对齐,使左侧全部垂直对齐。

Here is a simple ipython example, 这是一个简单的ipython示例,

from IPython.html import widgets # Widget definitions
from IPython.display import display # Used to display widgets in the notebook
small_widget = widgets.FloatTextWidget(description="Small:")
short_widget = widgets.FloatTextWidget(description="Also Short:")
long_widget = widgets.FloatTextWidget(description="Loooooooong:")

container = widgets.ContainerWidget(children=[small_widget, 
                                              short_widget, long_widget])

display(container)

You can see that for the Looooooong widget the label shifts the input box over considerably. 您可以看到,对于Looooooong小部件,标签将输入框大大地移动了。 I would like all of the other input boxes to also shift to the right to align. 我希望所有其他输入框也移到右侧以对齐。

Any suggestions on how to properly align these components (label, input box) of the FloatTextWidget? 关于如何正确对齐FloatTextWidget的这些组件(标签,输入框)的任何建议? I have looked at the IPython notebook on aligning widgets but it applies to an entire widget as a whole, not the individual label and field. 我看过有关对齐小部件的IPython笔记本 ,但是它适用于整个小部件,而不是单个标签和字段。

A quick fix is to increase the label widths by altering the CSS using an %%html cell: 一个快速的解决方法是通过使用%%html单元格更改CSS来增加标签宽度:

%%html
<style>
.widget-hlabel {
    /* Horizontal Label */
    min-width      : 10ex;
}
</style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM