Aligning TextBox Widgets in IPython Notebooks

半世苍凉 提交于 2020-01-23 17:59:30

问题


I am trying to make an IPython notebook more aesthetic by aligning input fields. 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,

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. 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? 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.


回答1:


A quick fix is to increase the label widths by altering the CSS using an %%html cell:

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


来源:https://stackoverflow.com/questions/26534123/aligning-textbox-widgets-in-ipython-notebooks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!