skip to Main Content

I have a table that is 650px wide and I add words to this table…each word is in its own cell.
However if I have too many words then it expands the table.
What I want to do is allow it to limit the X and auto go to a new row or under the current content so it doesn’t resize the table.

I thought about calculating the width of each cell using JS..but it says each is 0px as the cells are created programmatically using JS.

2

Answers


  1. Chosen as BEST ANSWER

    I got it work by using

     #tGrammar {
      display: block;
      }
    
     #tGrammar td {
      display: inline-block;
      }
    

    in CSS

    and in JS where is tChoicesMain is table

    tChoicesMain.style.tableLayout = "fixed";
    tChoicesMain.style.maxWidth = "650px";
    tChoicesMain.setAttribute("id", "tGrammar");
    

  2. Perhaps a table is not the best solution for you, since it doesn’t have this functionality.

    You could try simple <div>‘s, they will wrap, but you could also have a look at the newer, and more advanced, Flexbox. Have a look at the Wrapping section on that page.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search