CSS CSS style for output to IPython computer

I am trying to generate html table output for IPython output cells with an external css file. I would like to help understand how to do this, and created a couple of test cases for research. Neither the lowercase, nor the outermost style behaves as I expect -

External, which I hope to do:

htmlstr = "<html><head><link rel='stylesheet' type=\"text/css\" href=\"local.css\"></head><body>TEST BODY</body></html>" HTML(htmlstr) 

The file is not readable. I tried different paths and moved the file; but it does not seem to be recognized.


Inner style:

 htmlstr = "<html><head><style>body {background-color:yellow;}</style></head><body>TEST BODY</body></html>" HTML(htmlstr) 

Doing this in IPython changes the background of IPython itself. These are background changes for yellow for all IPython, and the input cells remain white. This is pretty cool; but, I want the style of a specific output. And again I want to save CSS in an external file. Can someone help me understand the behavior?

IPython is great for providing many features, and it is possible that there is a better way for my need.

+6
source share
1 answer

You can simply use more specific CSS properties! For instance. in the markdown cell (or custom.css with the default external file for styling the laptop and its contents)

 <style> th { background-color:#55FF33; } td { background-color:#00FFFF; } </style> 

with the following code

 from IPython.display import HTML table = "<table><tr><th>bar</th><th>bar</th></tr><tr><td>foo</td><td>foo</td></tr></table>" HTML(table) 

gives
enter image description here

+4
source

Source: https://habr.com/ru/post/958575/


All Articles