简体   繁体   中英

Aligning TextBox Widgets in IPython Notebooks

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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