如何确保动态生成的表上的等宽列 [英] How to ensure equal width columns on a dynamically generated table

查看:37
本文介绍了如何确保动态生成的表上的等宽列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我在帖子之前尝试搜索这个但是它并不是一件容易搜索的东西而且我不确定这是否会更多在ASP.NET论坛或这里。


我正在使用ASP.NET来获取数据库值并将它们组成一个表行。上下文是我有一个属性列表。我需要生成标题,这个表行位于其他一长串列表之上。


问题是,有时候我可能有4列,有时候我可能有5列,有时是6列,有时候是7.我总是拥有相同的433像素宽的表。如果我没有在TD上设置width属性,那么当我真正想要相等的宽度时,我最终会得到任意大小的列。


有没有简单的方法可以创建总长度相等的表格列,只需要知道整个表格宽度而不知道会有多少列?

解决方案

在不知道列数的情况下,如果内容不相等,那就不可能了。


非常感谢。我想我将不得不用C#代码来设置适当的宽度,这是我希望避免的:(



不知道列数,如果内容不相等,则不可能。

事情只有在它们不存在之前才是不可能的。


http://freachable.net/2007/11/02/AutomaticEqualWidthColumnsInHTMLTables.aspx


诀窍涉及使用小百分比宽度。


< style>

table.equalwidthcolumns tr td {width:5%;}

< /风格>


Hi all,

I tried searching for this before posting but it''s not exactly something that is easy to search for and I''m not sure if this falls more under the ASP.NET forum or here.

I''m using ASP.NET to get database values and forming them into a single table row. The context is that I have a list of "attributes" that I need to generate headings for and this table row sits above a long list of other things.

The problem is, sometimes I might have 4 columns, sometimes I might have 5, sometimes 6, sometimes 7. I always have the same 433 pixel-wide table though. If I don''t set the width property on the TDs, I end up with arbitrarily-sized columns when I actually want equal width.

Is there any easy way to create table columns that are always equal width when you only definitely know the full table width without knowing how many columns there will be?

解决方案

Without knowing the number of columns, and if the content is unequal, then it''s not possible.


Much thanks. I guess I will have to do something with C# code to set the proper width, which I was hoping to avoid :(


Without knowing the number of columns, and if the content is unequal, then it''s not possible.

"Things are only impossible until they''re not."

http://freachable.net/2007/11/02/AutomaticEqualWidthColumnsInHTMLTables.aspx

The trick involves styling the table column with a small percentage width.

<style>
table.equalwidthcolumns tr td { width:5%; }
</style>


这篇关于如何确保动态生成的表上的等宽列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆