【问题标题】:Setting column width in html & making table fit screen在 html 中设置列​​宽 & 使表格适合屏幕
【发布时间】:2018-09-12 02:54:21
【问题描述】:

我正在使用漂亮的汤编辑 difflib 生成的 html 代码。

html 代码生成一个表格。最初表格太大了,但我像这样更新了 html:

differencehtml = re.sub("table cellpadding=\"0\"", "table cellpadding=\"0\" style = \"table-layout:fixed\" width = \"100%\"", differencehtml)

添加样式和宽度规范使表格适合屏幕(哇!),但它也使所有列具有相同的宽度。

我尝试添加此代码来指定每列的宽度:

differencehtml = re.sub("td class=\"diff_next\"", "td class=\"diff_next\" width = \"5%\"", differencehtml)
differencehtml = re.sub("td class=\"diff_header\"", "td class=\"diff_header\" width = \"5%\"", differencehtml)
differencehtml = re.sub("td nowrap=\"nowrap\"", "td style = \"word-wrap: break-word\" width = \"40%\"", differencehtml)

但它没有影响。 (旁注 - 这些列宽加起来是 50%,但是这些 td 中的每一个在每行中出现两次,所以它加起来是 100%)

如何设置列宽?

【问题讨论】:

    标签: python html html-table


    【解决方案1】:

    我想通了 - 我需要编辑第 th 元素,而不是 td。 这里有用的信息:https://css-tricks.com/fixing-tables-long-strings/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-13
      • 1970-01-01
      • 2020-12-07
      • 1970-01-01
      • 2021-07-02
      • 2021-04-01
      • 1970-01-01
      相关资源
      最近更新 更多