# CSS style are not working on a table generated in a loop

**URL:** <https://community.plotly.com/t/css-style-are-not-working-on-a-table-generated-in-a-loop/58367>\
**Category:** Dash Python\
**Created:** [November 12, 2021, 1:48pm UTC](https://community.plotly.com/t/css-style-are-not-working-on-a-table-generated-in-a-loop/58367 "2021-11-12T13:48:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tannin.rusk](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tannin.rusk](https://community.plotly.com/u/tannin.rusk)\
**Post date:** [November 12, 2021, 1:48pm UTC](https://community.plotly.com/t/css-style-are-not-working-on-a-table-generated-in-a-loop/58367/1 "2021-11-12T13:48:18Z")

</div>

Hello,

I’m printing tables in a loop into the dom, and I’m running into a problem.  
The style attributes are somehow not working on the table.

This is the loop:

```auto
def cdr_df_loop(i):
    return dash_table.DataTable(
        data=cdr_df[i].to_dict('records'),
        columns=[{'id': c, 'name': c} for c in columns_cdr],

        style_header=style_header,
        style_cell=style_cell,
        style_data_conditional=style_data_conditional,
        style_table=style_table_cdr,
        fill_width=False,
        
        )

```

the style:

```auto
style_table_cdr={
        
       'borderRadius':'10px 10px',
       'marginBottom': 30,
       'marginTop': 30,
        #'height': '1000px',
        'overflowY': 'auto'
}

```

and the layout:

`html.Div(children=[cdr_df_loop(i) for i in months], style=margin),`

The problem is that there’s no margin between the tables.  
Here’s an illustration how it is:

 ![Bildschirmfoto 2021-11-12 um 14.44.47](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/f/b/fb916dd5a32fa3421e00366bd32b3c34145f55b8.jpeg)

This is what i want:

 ![Bildschirmfoto 2021-11-12 um 14.45.45](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/b/2/b2964791b4fb42d09cca13085c7c5d673089c37b.jpeg)

Why is the margin not applied?

Thank you!

---

<div class="post-metadata">

**Author:** ![tannin.rusk](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tannin.rusk](https://community.plotly.com/u/tannin.rusk)\
**Post date:** [November 12, 2021, 1:59pm UTC](https://community.plotly.com/t/css-style-are-not-working-on-a-table-generated-in-a-loop/58367/2 "2021-11-12T13:59:52Z")

</div>

ok I assume it’s because the `html.div` is not looped?

I change the method to involve the html.div:

```auto
def cdr_df_loop(i):
    return html.Div([ dash_table.DataTable(
        data=cdr_df[i].to_dict('records'),
        columns=[{'id': c, 'name': c} for c in columns_cdr],

        style_header=style_header,
        style_cell=style_cell,
        style_data_conditional=style_data_conditional,
        style_table=style_table_cdr,
        fill_width=False,
        
                                        )
                ],style=margin),

```

… in the layout I tried :

`html.Div([cdr_df_loop(i) for i in months])`

and

`html.Div(children=[cdr_df_loop(i) for i in months], style=margin)`

I don’t get an error but nothing is displayed

---

<div class="post-metadata">

**Author:** ![jlfsjunior](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jlfsjunior/32/16061_2.png) [@jlfsjunior](https://community.plotly.com/u/jlfsjunior)\
**Post date:** [November 12, 2021, 4:15pm UTC](https://community.plotly.com/t/css-style-are-not-working-on-a-table-generated-in-a-loop/58367/3 "2021-11-12T16:15:59Z")

</div>

Hi,

Have you tried using “30px” instead of 30 in any of your first method?

---

<div class="post-metadata">

**Author:** ![tannin.rusk](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tannin.rusk](https://community.plotly.com/u/tannin.rusk)\
**Post date:** [November 12, 2021, 4:21pm UTC](https://community.plotly.com/t/css-style-are-not-working-on-a-table-generated-in-a-loop/58367/4 "2021-11-12T16:21:16Z")

</div>

Hi!  
I tried it, but unfortunately that’s not the issue

---

<div class="post-metadata">

**Author:** ![jlfsjunior](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jlfsjunior/32/16061_2.png) [@jlfsjunior](https://community.plotly.com/u/jlfsjunior)\
**Post date:** [November 12, 2021, 4:44pm UTC](https://community.plotly.com/t/css-style-are-not-working-on-a-table-generated-in-a-loop/58367/5 "2021-11-12T16:44:56Z")

</div>

That’s odd… It worked for me fine:

 ![Screenshot 2021-11-12 at 17.44.07](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/2/1/218928fd6c762faaa543648c6e49f80e87d468ed.png)

Here’s my code:

```auto
from dash import Dash, html, dash_table
import plotly.express as px

app = Dash( __name__ )

df = px.data.iris().head(2)

def cdr_df_loop(i):
    return dash_table.DataTable(
            data=df.to_dict("records"),
            columns=[{"id": c, "name": c} for c in df.columns],
            style_table={
                "marginBottom": 30,
                'marginTop': 30,
            },
            fill_width=False,
        )

app.layout = html.Div([cdr_df_loop(i) for i in range(3)])

if __name__ == " __main__":
    app.run_server(debug=True)

```

---

<div class="post-metadata">

**Author:** ![tannin.rusk](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tannin.rusk](https://community.plotly.com/u/tannin.rusk)\
**Post date:** [November 12, 2021, 4:51pm UTC](https://community.plotly.com/t/css-style-are-not-working-on-a-table-generated-in-a-loop/58367/6 "2021-11-12T16:51:22Z")

</div>

That’s indeed odd
