CSS for Markdown only

I have a giant multi-page Dash app written with many tables. Within my assets/css file I have td defined without a border as I prefer that for the table styling of the app.

However when I use dcc.Markdown, the same styles are utilized and documentation oriented tables look terrible without the border. Adding border: 1px; to my td definition puts a border around the markdown tables that I want but then extends into the styling of my app pages.

Is there any way to define css, or unique style definitions for the markdown pages only? Or any way to define and apply a style such as td-markdown?

Without using selector?
Please follow this below.

Hi @marketemp

Try defining a class with the style for your markdown tables. For example:


.md-table table {
     border-collapse: collapse;
}

.md-table th, .md-table td {
  border: 1px solid;
}


Then apply this class to the dcc.Markdown() or any container that you want this style applied to


dcc.Markdown("""
| Syntax      | Description |
| ----------- | ----------- |
| Header      | Title       |
| Paragraph   | Text        |
    
""", className="md-table")

1 Like

Thanks @AnnMarieW that was exactly what I needed.

Not to get this question too fancy, but I am using < br / > (minus the spaces, made a newline in the forum post) for newlines within my table cells and now those are text. Is there any way to retain that or should I just live without them. Having that border back and understanding how to style, any more if necessary will be a big help.

Yes, you can use

dcc.Markdown(...., dangerously_allow_html=True)

However, you should be aware that this can introduce security risks - For more information see:

If you are displaying trusted data, this shouldn’t be a problem, but if you are displaying data from user input or extracted from a large database, there is a potential to create an XSS vulnerability

thanks @AnnMarieW now my Markdown is perfect.

I have used dangerously_allow_html=True in another project, creating simple enormous tables that takes forever with the html.Table,Tr,Td calls so I am aware of of it. Glad we got this working and it was a Dash lesson and not just a CSS lesson!

1 Like