How to set width in a td

In a <table>, how do I set the first column's width to be by the <td>'s max content width?
19 Replies
MarkBoots
MarkBoots•3y ago
you mean that the text won't wrap in the first column? max-content unfortunatly doesnt work on td's or th's. but you can prevent the text wrapping if so, you could do
table > tr > :where(td,th):first-of-type{
white-space: nowrap;
}
table > tr > :where(td,th):first-of-type{
white-space: nowrap;
}
Avi
Avi•3y ago
Why did I not think of that lol
MarkBoots
MarkBoots•3y ago
could be shorter btw. that one was maybe a bit overkill for specificity tr > :first-child
Avi
Avi•3y ago
td:first-of-type {
white-space: nowrap
}
td:first-of-type {
white-space: nowrap
}
MarkBoots
MarkBoots•3y ago
depends a bit on what you want/need. don't know if you have more tables, what's inside. if you have thead, tbody. if you use td/th.... but the white-space is what does the trick
Avi
Avi•3y ago
It's an options page in a Chrome extension that is only used to display info
Avi
Avi•3y ago
Now trying to figure out how to remove the bottom border from the last 2 cells
MarkBoots
MarkBoots•3y ago
tr:last-child > td { border-bottom: none }
Avi
Avi•3y ago
Noice Any idea how to remove the gaps between the cell borders? It's been a while since I messed with actual tables
MarkBoots
MarkBoots•3y ago
border-collapse: collapse on the table
Avi
Avi•3y ago
Nicely done
MarkBoots
MarkBoots•3y ago
* I still knew ... but did you know there are online resources too? * 😉
Avi
Avi•3y ago
"what css unit to use for td width" lmao
MarkBoots
MarkBoots•3y ago
in this case, you could have only gave the tr's a border bottom
tr:not(:last-child) { border-bottom: 1px solid white }
/* every row, but not the last one */
tr:not(:last-child) { border-bottom: 1px solid white }
/* every row, but not the last one */
Avi
Avi•3y ago
I want to support both light and dark theme though So I control the dark theme styling via a media query Oh
MarkBoots
MarkBoots•3y ago
I'll let you try yourself first. Learning how to use online resources is a skill too
Avi
Avi•3y ago
As it turns out, I don't have to apply a white border as the initial's value turns to white when the body's color is white Don't worry, I've been doing it all day with other projects Right now it's 1 AM so my brain's CPU clock is lower
MarkBoots
MarkBoots•3y ago
same here, after midnight. this was the last discord check. You're my last 'customer' :p
Avi
Avi•3y ago
lmao Overall I'm happy with how the little page looks like Though I should probably test on Firefox as well as it's a different beast
Want results from more Discord servers?
Add your server