Replies: 1 comment
|
Reflex does not have a direct built-in syntax for Option 1: Use You can inject arbitrary CSS using def index() -> rx.Component:
return rx.fragment(
rx.el.style("""
.container:has(div:hover) {
color: red;
}
"""),
rx.box(
rx.box("Hover me"),
class_name="container",
),
)Option 2: Use the Define your styles in a CSS file or a style dict at the app level, then apply class names: # In your rxconfig or app setup:
app = rx.App(
stylesheets=["/custom.css"],
)Then in .container:has(div:hover) {
color: red;
}And in your component: rx.box(
rx.box("Hover over this div"),
class_name="container",
)Option 3: State-based approach (if you need it reactive) If you need Python-level control, you can use event handlers instead of pure CSS: class State(rx.State):
child_hovered: bool = False
def index() -> rx.Component:
return rx.box(
rx.box(
"Hover me",
on_mouse_enter=State.set_child_hovered(True),
on_mouse_leave=State.set_child_hovered(False),
),
color=rx.cond(State.child_hovered, "red", "inherit"),
)The raw CSS approach is usually the cleanest for pure styling concerns like this. The |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I can't figure out how to use :has. Pseudo-classes like hover goes something like:
_hover={"color": "red"},
If I want to write something like this:
.container:has(div:hover){
color: red;
}
Is this possible in Reflex? If so, how should I write it?
Thank you all.
All reactions