0

I'm trying to understand if it is possible to set the width of a table cell or column to either:

  1. a fixed % width
  2. a fixed px width

And, regardless of its content - it stay that width.

However, the scenario is that the first column needs to be longer than the rest. So if I have 10 columns, the first is larger and the other 9 are equally spaced.

I have tried the following but it does not work:

table{display:block;overflow:hidden;}
th td {max-width:2%;overflow:hidden;white-space:nowrap;}
th.question {width:60%;overflow:hidden;white-space:nowrap;}
td.question {width:60%;overflow:hidden;white-space:nowrap;}

Is it possible to achieve a fixed width

1 Answer 1

1

Is it possible to achieve a fixed width

Yes , if you set the propertie to fixed for the table-layout rule on <table> or on any displayed as table element.

See W3C : http://www.w3.org/wiki/CSS/Properties/table-layout

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the reply - however, this creates all columns to be equally spaced - which is not the solution I am looking for, as described above.
give a try and understand how this works, else why should i answer :)
I've added table-layout: fixed; to the code above and no joy.
Can you give a link to a fiddle or codepen so, we see how you applied width and table-layout :)
I've been playing and you can set the width of columns in a 'fixed' width scenario and all working as it should!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.