Skip to content

CSS

plotjs offers a few utility functions to work with CSS, and a guide on how to work with CSS.

Warning

You likely just want to use the add_css() method from the PlotJS object instead of the following functions. Those are used under the hood and you can use them, but they might not provide you the simplest interface.


plotjs.css.from_dict(css_dict)

Get raw CSS in a string from a dictionnary. It's a utility function useful to write CSS from a Python dictionnary.

Parameters:

Name Type Description Default
css_dict dict

A dictionnary with keys (selectors) and value (dictionnary of property-value).

required

Returns:

Type Description
str

A string of raw CSS.

Examples:

from plotjs import css

css.from_dict({
    ".tooltip": {"color": "red", "background": "blue !important"},
    ".point": {"width": "10px", "height": "200px"},
})


plotjs.css.from_file(css_file)

Get raw CSS from a CSS file. This function just reads the CSS from a given file and checks that it looks like valid CSS.

Parameters:

Name Type Description Default
css_file str

Path to a CSS file.

required

Returns:

Type Description
str

A string of raw CSS

Examples:

from plotjs import css

css.from_file("path/to/style.css")


plotjs.css.is_css_like(s)

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

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 plotjs 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