I am working on a Python 3 notebook in Google Colab. I would like to use a CSS file to change the header styles (color, font, etc.) and change numbered sub-lists to alphabetical. I need help importing the CSS into a Colab notebook.
Here is the Markdown code:
# List
1. item
1. item
1. item
1. sub-item
1. sub-item
1. sub-item
It renders as:
Here's the CSS:
ol ol {
list-style-type: lower-roman;
}
h1 {
color: red;
}
I want it to render as:
In the advanced_outputs example from Colab, there is a reference to how to enable MathJax in Colab. This requires adding a handler that is triggered on each cell creation. This method can be changed to add in a CSS element instead of including the MathJax JavaScript source.
The @import rule allows you to import a style sheet into another style sheet. The @import rule must be at the top of the document (but after any @charset declaration). The @import rule also supports media queries, so you can allow the import to be media-dependent.
This is a hacky answer, but it seems to work. In the advanced_outputs
example from Colab, there is a reference to how to enable MathJax in Colab. This requires adding a handler that is triggered on each cell creation. This method can be changed to add in a CSS element instead of including the MathJax JavaScript source.
from IPython.display import Math, HTML, display
def set_css_in_cell_output():
display(HTML("""<style>
ol ol {
list-style-type: lower-roman;
}
h1 {
color: red;
}
</style>"""))
get_ipython().events.register('pre_run_cell', set_css_in_cell_output)
After running this cell, every new output cell in your notebook will have that CSS added to it. From my own experience, I often end up having to use !important
on rules because the CSS hierarchy can get quite complicated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With