Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Does IDOM support CSS modules? #478

Answered by rmorshea
Archmonger asked this question in Question
Discussion options

I was reading up about React and was wondering if IDOM has an integrated way of implementing CSS modules.

ex) https://www.w3schools.com/react/react_css.asp

You must be logged in to vote

You can add style to elements in two ways:

  1. with a style tag element
  2. using the style prop (as in React)
# style element (write a CSS string)
html.style(".some-css {...}")
# define style the same as React with a camelCased dict
html.div({"style": {"backgroundColor": "red"})

Replies: 2 comments 5 replies

Comment options

You can add style to elements in two ways:

  1. with a style tag element
  2. using the style prop (as in React)
# style element (write a CSS string)
html.style(".some-css {...}")
# define style the same as React with a camelCased dict
html.div({"style": {"backgroundColor": "red"})
You must be logged in to vote
5 replies
Comment options

Can style be updated with hooked variables?

For example:

bgstate, set_bgstate = idom.hooks.use_state("red")
html.div({"style": {"backgroundColor": bgstate})

I've tried this and can't get it to work. It will start red but when calling set_bgstate() it doesn't change.

Any tips?

Comment options

Yup that's a bug. That's probably also why the snake game from the examples is broken right now too.

Comment options

Tracking it here: #480

Comment options

@jgburford without that little hint it would have taken me ages to debug the underlying issue. Thanks! 🙏

Comment options

@rmorshea glad I could be of some help!

Answer selected by Archmonger
Comment options

Archmonger
Apr 7, 2022
Maintainer Author

I don't think it's technologically possible for IDOM to have scoped CSS, such as with css-modules.

The only viable solution is inline styles, as mentioned above

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /