Please consider this notebook found on github:
There are four styling examples. The first three work. For the first three I would like to know if this is ‘legal’ widget code. I.e. is this likely to break in future versions, or is this the way it is supposed to be done?
In the first example, a class is created inside style tags, and then is used within a single string constant that is given to a single ipywidgets.HTML widget. If anything is going to work, it seems this would. And it does.
In the second example there are two ipywidgets.HTML widgets. Both are children of the same Box. In the first one the class is defined. In the second one it is used. This works. Hence it appears that a style definition that occurs within style tags is available to all children of a Box. … but wait there is more.
In the third example, a new Box is created that does not contain any class definitions. Instead it has a single HTML widget child, and that child successfully makes use of the prior two class definitions. So apparently what is in the style tags applies to all the HTML widgets … and there is more yet.
Within the style tags there is styling for h1 tags. The markdown in the jupyter notebook itself is changed by that. Hence, the stuff in style tags affects the whole notebook, no matter where those widgets are anchored as children.
This is actually nice. A programmer can even just include an single HTML block with all the style and class definitions at the top for the notebook, including the jupyter notebook markdown cells, just like a person might do with the header of an html page.
Putting style at the top of the notebook. Can define classes to use etc. … this example will make h1 purple, even in the markdown cells:
import ipywidgets as W
display( W.HTML( '''
<style>
h1 {
color: purple;
}
</style>
'''))
But is this going to still work in future versions? Is this the way it is supposed to work?
As for the 4th example, the Box has three HTML children. The first opens a div. The second has the contents for the div. The third then closes the div. This does not work. So apparently each HTML widget is contained in a div of its own. We are not just laying down HTML as we run across it. But that means our style tags are within a div. HTML will still consider those to be global to the page, which is why this is working. I guess.
Oh gee, I guess script tags will also work.