0

I have two tables next to each other, one has overflow set to auto to scroll across if there are more than X columns.

I want to have the columns in this scrollable table a fixed width which I've set with CSS. When there is just a few columns, the fixed width works.

When there is more three columns and it hits the overflow, the CSS width does not work, the column is just sized based on the text.

JSFiddle single column: https://jsfiddle.net/u4onfzzs/

JSFiddle multi-column: https://jsfiddle.net/eb5ts6c6/

Here's the CSS that is being ignored on the multi-col

#content .fixedColumn td.dataCol
{
    width:150px;
    padding:6px 0px 7px 8px;
}

I'm stumped.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Tom
  • 4,467
  • 17
  • 59
  • 91
  • Set the width of the th, and the column should conform. – Lansana Camara Aug 08 '17 at 14:58
  • If I change the CSS to `#content .fixedColumn td.dataCol` and then add that class to the table header, it still doesn't work for multi-cols – Tom Aug 08 '17 at 15:01
  • That's because the table header should be targeted with `th` in the CSS, not with `td`. So change `td.dataCol` to `th.dataCol`. But generally speaking, if you have a table with a few columns and each column has a header, when you set the width of the header, the column will update accordingly. Tables suck though, and sometimes they don't get set if you don't set all columns/headers and only set one of them somewhere in the middle. – Lansana Camara Aug 08 '17 at 15:08
  • I did change the CSS and updated the HTML. Still doesn't work. So frustrating...https://jsfiddle.net/eb5ts6c6/1/ – Tom Aug 08 '17 at 15:16
  • 1
    In the CSS where you set width of th, change `width` to `min-width`. This works: https://jsfiddle.net/eb5ts6c6/2/ – Lansana Camara Aug 08 '17 at 15:18
  • Perfect, that works. Post it as an answer and I'll check it off. – Tom Aug 08 '17 at 15:30

1 Answers1

1

In your fiddle here, you set width of th in your CSS. Change width to min-width and your columns should resize accordingly.

Example fiddle.

Lansana Camara
  • 9,497
  • 11
  • 47
  • 87