Skip to content

Css

css

Utility class to handle CSS injection for interactive plots.

This class provides multiple ways to load CSS: directly from a string, from a dictionary, or from a CSS file. It is intended to be combined with interactive plots.

Parameters:

Name Type Description Default
from_string str

CSS rules in a string.

None
from_dict Mapping[str, Mapping[str, object]]

Dictionary containing selectors as keys and dictionaries of property-value pairs as values.

None
from_file str

Path to a CSS file.

None
(
    interactive(p)
    + css(".tooltip { font-size: 2rem; }")
    + css(from_dict={".tooltip": {"font-size": "2rem"}})
    + css(from_file="style.css")
    + save("output.html")
)

is_css_like(s)

Check whether a string looks like valid CSS. This function is primarily used internally, but you can also use it directly.

Parameters:

Name Type Description Default
s str

A string to evaluate.

required

Returns:

Type Description
bool

Whether or not s looks like valid CSS.

Examples:

from ninejs.css import is_css_like

is_css_like("This is not CSS.") # False
is_css_like(".box { broken }") # False
is_css_like(".tooltip { color: red; background: blue; }") # True