简体   繁体   English

HTML:tds的固定宽度和可变宽度

[英]HTML: fixed and variable width of tds

i have a <table> and many (34) <td> . 我有一个<table>和许多(34) <td>

I want to display three variable cells eg "name", "hobby1", "hobby2" and then I need to display 31 cells (for each day). 我想显示三个变量单元格,例如“名称”,“ hobby1”,“ hobby2”,然后我需要显示31个单元格(每天)。

The width of the <table> is limited to about 1000px. <table>的宽度限制为大约1000像素。

In the day cells always a string of the length 3 shall be displayed or nothing. 在白天的单元格中,始终显示长度为3的字符串或不显示任何内容。

My problem is that, the cells never have the same width even if set with css. 我的问题是,即使使用css设置,单元也永远不会具有相同的宽度。

The first three columns may be fixed too. 前三列也可能是固定的。

How can I manage my table, that all day <td> s (1-31) have the same width - no matter if the content is nothing or XXX? 如何管理我的表,整天<td> s(1-31)的宽度相同-无论内容为空还是XXX?

http://jsfiddle.net/sBYdu/ http://jsfiddle.net/sBYdu/

A couple of css additions can achieve this. 几个CSS附加功能可以实现此目的。

  • Use a fixed table-layout 使用固定的表格布局
  • Apply width to your table header not the table cell 将宽度应用于表格标题而不是表格单元格
  • Apply word wrapping to the table cells 将自动换行应用于表格单元格

http://jsfiddle.net/nnePW/ http://jsfiddle.net/nnePW/

table {

    table-layout: fixed;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM