Skip to content

Need a way to style a components children in Yew #35

Answered by WorldSEnder
Madoshakalaka asked this question in Q&A
Discussion options

You must be logged in to vote

The following example seems to work for me

        let children = (0..5).map(|i| html! {<li><span>{format!("Item: {}", i)}</span></li>});
        let container = css!(
            r#"
            display: grid;
            & li {
                color: green;
            }"#
        );
        html! {
            <div class=self.style()>
                <ul class={container}>
                    {for children}
                </ul>
            </div>
        }

This applies the display: grid to the <ul> item, and the color: green to the individual children. Can you post the css you tried? If you used inline style, it might have to do with spacing issues.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by WorldSEnder
Comment options

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
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #34 on September 02, 2021 15:58.