Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tables should look good, and like tables, by default #39

Open
eallenOP opened this issue Mar 6, 2019 · 14 comments
Open

Tables should look good, and like tables, by default #39

eallenOP opened this issue Mar 6, 2019 · 14 comments

Comments

@eallenOP
Copy link

eallenOP commented Mar 6, 2019

From: https://wiki.csswg.org/ideas/mistakes

For example, who ever wanted non-collapsed borders (or no borders) by default? Not sure if borders count as layout though...

Padding? Tables without padding are not readable.

@jensimmons
Copy link
Owner

This sounds good.
Do you have some suggestions for code to add to Remedy?
(You can write it here so we can discuss, no need to be sure / make a pull request.)

@tylersticka
Copy link

tylersticka commented Mar 8, 2019

I took a look through our last several design system projects, and found a surprising amount of variation (to me, anyway) between table styles when it came to properties like padding, border-spacing and even width (I really thought we'd be applying width: 100%, but I found two projects where we are not).

These styles were the only ones that we seemed to consistently apply as defaults:

/**
 * 1. Prevent double borders
 * 2. Without this, th elements won't inherit their alignment predictably in
 *    Safari. Setting alignment here makes it easier to override on the
 *    containing element (if desired).
 */

table {
  border-collapse: collapse; /* 1 */
  text-align: left; /* 2 */
}

/**
 * Make th alignment consistent with td alignment
 */

th {
  text-align: inherit;
}

This doesn't address the proposed padding readability issue, and our techniques, customers and end users may differ from others, but I thought I'd provide as a point of discussion and consideration. 🙂

@eallenOP
Copy link
Author

How opinionated should this be? For example, is a table more table-ish when it has borders than when it doesn't? Is there any use at all in a table where every bit of content is squished right up against its neighbours? If we do want padding, how would we decide how much?

In which case do we add something like:

th, td {
  border: 1px solid black;
  padding: 5px;
}

or is this way too opinionated (and everyone will set their own table styles anyway)?

@hacknug
Copy link

hacknug commented Mar 12, 2019

The amount of padding should/could be consistent with the spacing scale used for headings and paragraphs.

@tylersticka
Copy link

tylersticka commented Mar 12, 2019

or is this way too opinionated (and everyone will set their own table styles anyway)?

I hope others will chime in (as I wouldn't want direction to be informed by my team's experience alone), but border and padding styles are among the first things that we seem to customize per project (and not consistently so). My instinct would be to leave them out.

(If I'm wrong about that, I'd consider using currentColor instead of black for the border?)

@scottkellum
Copy link

I like it! I’d maybe amend it to be like this

th, td {
  border: 1px solid;
  padding: 0.5rem;
}

currentColor is the default for border so there is no need to write it. Also padding in rem allows it to fit better with the chosen base font size so it can scale up and down based on foundational design decisions of that project.

@meyerweb
Copy link

Perhaps the padding should be rem-based in the inline direction, and em-based in the block direction, something like padding: 0.2em 0.5rem 0.1em. Although this is starting to get pretty opinionated.

@eallenOP
Copy link
Author

eallenOP commented Mar 14, 2019

There are kinda opinionated things that we all override already in CSS though, I guess. Otherwise everything would be as jammed together as tables are by default. Line height is an example - you've got to have some kind of line height by default (as discussed in #7 ). Also, how did it get decided how much margin to put on paragraphs by default (#1 )? I think table padding falls into this category too, and since we're moving away from everything being specified in exact pixels then yeah, rems and ems FTW.

So far we are up to

table {
  border-collapse: collapse;
  text-align: left;
}

th {
  text-align: inherit;
}

th, td {
  border: 1px solid;
  padding: 0.2em 0.5rem 0.1em;
}

This works in my world. Other perspectives?

@tylersticka
Copy link

tylersticka commented Mar 14, 2019

The only part of that code that feels too opinionated to me is the mismatched vertical padding. I'd simplify to something like 0.2em 0.5rem.

Just my two cents, though! 🙂

@meyerweb
Copy link

The mismatching helps vertically balance the text in the cell, because it compensates for the (roughly) tenth of an em below the baseline of the text, where there’s a lot of open space that’s not counted in vertical padding.

@tylersticka
Copy link

That makes a lot of sense for text. A lot of our customers use tables primarily for laying out specification data, and since that's often numeric, I find mismatched vertical padding less beneficial?

Mismatched Example

Screen Shot 2019-03-14 at 11 41 04 AM

Consistent Example

Screen Shot 2019-03-14 at 11 41 22 AM

(There are certainly other improvements to be made in these examples... text alignment, for instance... but wanted to provide a "for instance" rather quickly.)

On a scale of 1 to 10, my passion level on this is maybe a 3 or 4, so it's all good if we agree to disagree. 🙂

@scottkellum
Copy link

It might be worth adding font-variant-numeric: tabular-nums; to the table CSS to ensure the numbers line up.

@jensimmons
Copy link
Owner

Researching for something else entirely, I just ran across this excellent run-down on styling tables: https://css-tricks.com/complete-guide-table-element/

@jensimmons jensimmons changed the title Table layout should be sane Tables should look good, and like tables, by default Sep 20, 2019
@Malvoz
Copy link
Contributor

Malvoz commented Jun 5, 2020

From: https://wiki.csswg.org/ideas/mistakes

For example, who ever wanted non-collapsed borders (or no borders) by default?

Turns out border-collapse: collapse disables position: sticky (presumably for <thead> and <tr> elements), reference: https://bugs.chromium.org/p/chromium/issues/detail?id=702927#c35.

Additionally, overflow: hidden on <table> also disables stickyness, overflow: clip on the other hand might enable the intended behavior of hiding overflow and keeping stickyness, reference: w3c/csswg-drafts#865 (comment).

Not sure what to do with this information - perhaps it is out of scope - to include it as a CSS comment on sticky positioning in regards to tables?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants