-1

(有关结构和可能的内容,请参见下面的小部件图像)。所以这是交易:在我正在处理的应用程序中,有一个固定大小的小部件,内容可变。内容有 3 到 5 个“内容”容器,这些容器根据小部件的显示位置和时间而有所不同。但是,小部件本身始终具有相同的大小。

每个“容器”中的内容始终垂直和水平对齐到中心。组合(见下图)是:

  • 状态容器始终存在(容器 1)
  • 第二“行”有 1 个或两个容器;如果是一个,它跨越整个宽度;如果两个,每个是总数的 1/2
  • 第 3 行和第 2 行一样,增加/更改也可以为空

现在——正如我所见,有两种方法可以解决这个问题:Divs 和 Table。

如果是 div,它将类似于:

<div outer container>
 <div container 1></div>
 <div container 2>
  <div container 2a></div>
  <div container 2b></div>
 </div> end container 2
 <div container 3>
  <div container 3a></div>
  <div container 3b></div>
 </div> end container 3
</div> end outer container

如果它是一张桌子,它将是:

<table>
 <tr colspan=2><td>Container 1</td></tr>
 <tr><td>Container 2a</td><td>Container 2b</td></tr>
 <tr><td>Container 3a</td><td>Container 3b</td></tr>
</table>

如果第二个或第三个容器只有一个“列”,请适当地应用 colspan。

在我看来,表格方法更简单,特别是在水平和垂直对象对齐方面,但我想与其他人核实,因为我知道表格往往是禁止的。不过,我实际上认为在这里使用表格是合适的,因为它实际上将表格数据显示为其内容!

想法?

Widget 架构 http://www.5sn1.com/images/quantity_widget.png

4

3 回答 3

1

I would advise against going with whatever works for you. Yes, in the short term it would be the easiest method, however, maintaining/updating the layout later on may become more difficult. I would say don't only think of the 'now', but think about the expansion or say in future if another developer would need to take over the work.

Use what works for the site/app. If it is most important that the site UI is 100% picture perfect, or 100% cross browser compatible, or 100% validating code. Sadly, it is usually not possible to have all three situations. Thus, use what works for the site and is maintainable.

Personally I would use a table in displaying tabular data instead of juggling around DIVs if it made sense to do so.

于 2012-10-30T00:07:07.157 回答
1

In my opinion either methods are fine, although if you're aiming for those widgets to be cross-browser, you'll have less headaches using tables, like in vertical alignment like you mentioned. Just keep in mind that tables for layout is bad in most cases, but even i use them when the boss calls IE 7/8 to the table.

I don't think that example is considered tabular data, generally its something like a datagrid.

Anyways, like Kolink said, its up to you, just use the method that works for you.

于 2012-10-30T00:11:53.447 回答
1

使用表格进行布局通常不受欢迎,但没有真正的理由不使用它们。正如你所说,它确实使它更容易和更合乎逻辑。

总而言之,你真的应该选择适合你的。

于 2012-10-29T23:53:38.897 回答