Custom CSS for tables - 5 New styles, ready to use in your notes

Hi there!!

Sharing one more time my personal table styles but this time I got them all into one single css file with 5 table visuals and a few hacks that enable further customization:

The White red table has an extra mode that you can use to get it with rounded corners, all you gotta do is stack both classes:

cssclass: whiteRed, whiteRed-rounded, wideTable

The class wideTable draws the table 100%, so it takes your notes width by default. The use of these hacks is up to your personal choices, they are unrelated to main tables CSS, but can be stacked with them as shown above.

Other “hack” classes are:

  • leftAlign- Some themes use RTL in tables, this brings the content back to the left;

  • fixedFc- Fixes the first column width and avoids double lines by using “…” in long texts. Useful when your first column is a date or some other short text. Not to be used with the wideFc hack.

  • wideFc- For big texts in the first column, but you also want single lines, so this hack appends ellipsis to long texts in this column. I find it great for general notes list, particularly with the Dataview plugin that uses the file name as first column. Not to be used with the fixedFc hack.

  • customMargin- If you need some extra space between tables and your content, just call this guy.


Steps to use these tables:

  1. Put the attached CSS file into your vault snippets folder and make sure to enable it in your preferences > CSS Snipets option.

  2. In a note, use the frontmatter cssclass code with the chosen table/hacks:

---
   cssclass: purpleRed, wideTable, fixedFc
---
  1. Nothing else, that’s it :partying_face:

tableStyles.css (8.4 KB)

Tables.zip (3.4 KB)

The tables.zip file contains the .md files used in the screenshots. Just drop the folder in your vault and you should have a showcase of each table style!

Reminder:
Table visuals might change given your Obsidian theme/OS fonts. In the CSS file there are some examples of custom fonts being used, these should point you in the right direction to get same results as here.

32 Likes

Is it possible to have the Latex style with rounded corners?

Rounded modes can be quite annoying to fine tune but that was not the case for the Latex one. I literally just copied the White red rounded parts of the code to the academia class. The updated Latex like code looks like this:

    /* --------------------------------------------   */
    /* Latex table-layout:                            */
    /* --------------------------------------------   */
    .academia table {
    	border-collapse: collapse;
    	border-spacing: 0;
    	width: auto;
    	/*max-width: 100%;*/
    	border-top: 2.27px solid black;
    	border-bottom: 2.27px solid black;
    	overflow-x: auto;	
    	box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
    }
    .academia th,
    .academia td {
    	border: 0 none;
    	padding: 0.51rem;
    	line-height: 1.1;
    }
    .academia table > tbody > tr:first-child > td,
    .academia table > tbody > tr:first-child > th {
    	border-top: 1.36px solid black;
    }
    .academia table > tbody > tr:last-child > td,
    .academia table > tbody > tr:last-child > th {
    	border-bottom: 1.36px solid black;
    }
    .academia thead th {
        background-color: white !important;
        font-weight: 700;    
        padding: 8px 9px 8px 9px;
        font-size: 0.9em;
    }
    .academia tr:nth-child(even) {
          background-color: #ebecf1 ;
    }
    .academia tbody tr:hover td {
    	background-color: #f5f1da;
    }
    /* --------------------------------------------   */
    .academia-rounded table {
        border-collapse: separate;
        border: solid #b3b3b3 1px;
        border-radius: 6px;
        border-spacing: 0px;
    }
    .academia-rounded table > tbody > tr > td {
    	border-bottom: 1px solid #ccccccbb;
    }
    .academia-rounded table > tbody > tr:last-child > td {
    	border-bottom: thin #ccccccbb;
    }
    .academia-rounded table th:first-of-type{
    	border-top-left-radius: 6px;
    }
    .academia-rounded table th:last-of-type{
    	border-top-right-radius: 6px;
    }
    .academia-rounded table tr:last-child td:first-child {
        border-bottom-left-radius: 5px;
    }
    .academia-rounded table tr:last-child td:last-child {
        border-bottom-right-radius: 5px;
    }
    /* --------------------------------------------   */

The rounded class is stackable so this is the front matter:

---
cssclass: academia, academia-rounded
---

And you should have it with rounded edges:

2 Likes

Thank you !!

Hi @DeaconLight

I wanted to create an official looking food label in Obsidian, with just markdown tables. Had no idea where to start because I didn’t know what selectors there are for markdown tables. Then I stumbled upon this post of yours and I downloaded your files.

I could not have pulled this off without your well documented css file and examples. I adapted your yellowCab css extensively to re-create the original foodlabel I found as an image. I think I did a pretty good job, thanks to your examples.

I just used another font than the real label does. I don’t like Arial etc and use Avenir Next in my entire vault. But if someone wanted to, they could of course adapt the CSS and use another font.

I’ll attach my adapted CSS and the the 07 - Nutrition Facts.md file plus the foodlabel photo and a screenshot of my pure Markdown table + CSS Nutrition Facts FoodLabel.

Kind regards,

Fieke

Attachments:

nutFact_tableStyles.css (9.2 KB)

07 - Nutrition Facts.md (1.6 KB)


This is a picture of a real FoodLabel


This is a screenshot of my pure Markdown Table & CSS FoodLabel

7 Likes

Hello @FiekeB

This was an impressive work, it really looks perfect and well made, very proud I could help a little on this. The Avenir Next font looks really good, it’s the first time I notice it and I really like it, might even use it here.

Thank you for sharing this and the code, really good work!! Cheers

1 Like

Hey @DeaconLight, Avenir Next isn’t a free font as far as I know, I think it comes with Apple products like MacBook etc, but Montserrat is almost identical and a Google Font!

Thought I’d tell you in case you have no access to Avenir Next :slight_smile:

PS Thanks for your compliments, makes me feel proud ! (it took me 2 days to figure it all out, haha!)

3 Likes

@FiekeB can you believe I work on Macs for as long as I remember and never looked twice at this font? Thank you for the suggestion of an alternative as well, really thoughtful, I appreciate it. And god, only 2 days is amazing, looks just as the original! Cheers!!

1 Like

Great work - thank you for sharing. Is it possible to modify fixedFc so that all the columns avoid double lines by using “…”? At the moment only the second column does that. Thank you.

Thank you so much for this, it’s great!