What I’m trying to do
I want to build a custom table, so I wrote the HTML code and the CSS snippet to do so. But the result is inconsistent:
- In view-mode, I have a table that doesn’t look like what I asked for.
- In editor-mode (not source-mode), I have the table I asked for (but only when it is displayed on a second tab).
I don’t understand why the table is not the same on both tabs, nor in both modes.
Question to the Forum
How can I make sure that my table is consistently displayed like the right tab table? (see screenshot)
In other words: How can I make sure that Obsidian displays the table from the editor-mode (see right tab on the screenshot) onto the view-mode (see left tab on the screenshot)?
Attachments (HTML code)
<table border="1px solid black">
<caption>Caption table</caption>
<tbody>
<thead><tr><th>Left thead</th><th>Right thead</th></tr></thead>
<tr><td>Left cell</td>
<td>Right cell</td></tr>
<tr><td>Cell 1</td>
<td>Text 1</td></tr>
<tr><td>Cell 2</td>
<td>Text 2</td></tr>
<tr><td>Cell 3</td>
<td>Text 3</td></tr>
<tr><td class=cell-highlight>Cell 4 highlighted</td>
<td>Text 4</td></tr>
</tbody>
</table>
Attachments (CSS snippet)
table {
border: 1px solid black;
}
caption {
font-weight: bold;
font-size: 24px;
text-align: left;
color: #333;
margin-bottom: 14px;
}
th, td {
border-collapse: collapse;
padding: 8px;
}
thead th {
width: 25%;
background-color: #666666;
color: white;
font-size: 0.875rem;
text-transform: uppercase;
letter-spacing: 2%;
}
tbody tr:nth-child(odd) {
background-color: #fff;
}
tbody tr:nth-child(even) {
background-color: #eee;
}
tbody th {
background-color: #d7e3ee;
color: #fff;
text-align: left;
}
tbody tr:nth-child(even) th {
background-color: #b8cde0;
}
.cell-highlight {
background-color: #dfc76c;
font-weight: bold;
}
Other info
I have a custom ITS Theme
turned on, but the exact same issue occurs when I put back the Default Theme
, so I don’t think the theme is important for the solution.