@JayKim
Well I can’t get the table to be max width, the best I could get was a centered table which displays scrolls bars if the area is less than the table width.
.markdown-preview-view table {
display: block; /* This is needed for scrollbar */
width: 100%;
max-width: -moz-max-content;
max-width: max-content;
margin: 0 auto; /* this centers the table */
overflow-x: auto; /* This is needed for scrollbar */
white-space: nowrap; /* Keeps each cell on one line */
}
th { /* Not needed just colors the header bar */
background-color: var(--text-normal);
color: var(--background-primary);
}
tr:nth-child(even) { /* Not needed just colors even rows (aka zebra stripes) */
background-color: var(--text-faint);
color: var(--text-normal);
}
I’m not great with CSS but here is why i think what you are asking can’t be done 100%. Maybe someone who is better at CSSS can either confirm my theory or provide a correct explanation.
The link you give shows the DIV having the “overflow-x:auto;” to be able to use that in that way in obsidian there would need to be a named div for the table but there isn’t there is just a plain div.
in other words we would need for obsidian to name the div right before the table as something we could pick out uniquely such as
div.TableDiv { overflow-x:auto; }
But Obsidian doesn’t do that. If we try to add the overflow-x:auto; to the plain div tag
div {overflow-x:auto;}
that effects every div showing and adds scroll bars in lots of places where you probably wouldn’t want them.
So I don’t think it is possible at this time. The way mine works is I moved the overflow from the div to the table and also added block as overflow only works on block items.
The problem is when adding that block it makes the columns collapse to just the content size no matter if the width is set to 100% or something else.
If you want to see where I got most of this info it was on this stackoverflow post under the sub heading “The solution for those who cannot or do not want to wrap the table in a div (e.g. if the HTML is generated from Markdown) but still want to have scrollbars:”