Issue
For some reason, I want to my HTML widget to have fixed height, no matter how many lines there are in the widget. If the lines are too many to fit into the height, ideally one can scroll to see all the lines. I tried something like the following, but it does not work:
import ipywidgets as widgets
widgets.HTML(
value="Hello <p>World</p><p>World</p><p>World</p><p>World</p><p>World</p><p>World</p><p>World</p><p>World</p>",
placeholder='Some HTML',
description='Some HTML',
disabled=True,
height='50px',
overflow_y='scroll'
)
Solution
The follwoing code solves the problem:
import ipywidgets as widgets
from ipywidgets import Button, Layout
b=widgets.HTML(
value="Hello <p>World</p><p>World</p><p>World</p><p>World</p><p>World</p><p>World</p><p>World</p><p>World</p>",
placeholder='Some HTML',
description='Some HTML',
disabled=True
)
a = HBox([b], layout=Layout(height='50px', overflow_y='auto'))
display(a)
Interestingly, this does not work:
a = HBox([b], height='50px', overflow_y='auto')
It seems HBox
does not pass overflow_y
to the html/css, for some reason I don't understand.
Answered By - RNA
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.