Как я препятствую тому, чтобы моя таблица HTML простиралась

5 ответов

Вы, вероятно, захотите table-layout: fixed и установите ширину в первых ячейках строки.

См. http://www.w3.org/TR/CSS2/tables.html#fixed-table-layout для подробного объяснения.

24
ответ дан 30 November 2019 в 04:37
поделиться

Assuming you don't have any non-breaking spaces or super-long text without a space in the cell, I've usually had the best luck by explicitly setting the width of said cell via CSS (seems to work better than doing something like "width='100'". If the data in the cell is just a really long string, there's not much you can do other than truncate it programatically, or wrap the data in a div with an explicit width and something like overflow: hidden / auto (auto if you want a horizontal scrollbar or something).

0
ответ дан 30 November 2019 в 04:37
поделиться

Set the width and height of the td tag using CSS. Then you need to deal with overflow.

td {
  width: 40px;
  height: 20px;
}
0
ответ дан 30 November 2019 в 04:37
поделиться

Use overflow: hidden to hide the overflow as such:

td, th {
    overflow: hidden;
}

For this to work, your or tags needs to be assigned a width.

-3
ответ дан 30 November 2019 в 04:37
поделиться

If you must absolutely have the table maintain it's layout even in the face of non-breaking spaces, then you'll need to use:

 overflow: hidden;

However, I'd recommend against it. IMO, it's more important to have the data readable than the layout perfect.

-4
ответ дан 30 November 2019 в 04:37
поделиться