复杂表格table vs div
我在网上查找了使用 DIV 实现表单的示例,我看到的只是非常简单的一栏表单。我有一些非常复杂的表单,这是其中的一张图片:
http://img835。 imageshack.us/img835/8292/formn.jpg
让它与表格一起工作很容易(我就是这样做的),我唯一的问题是有时我需要不显示一些选择并将值向上移动一行以避免出现间隙。
我开始使用 div 制作一些表单,但是当我更改浏览器窗口大小时,它们会崩溃,并且对齐东西并不容易。
这个主题很有帮助: 使用的设计是否不好在 html 中显示表单时的表标签? 但它并没有解决我的一些担忧。
您会提出什么解决方案?我可以动态删除/插入表中的值或尝试执行 DIV。
I looked online for examples of implementation of the form using DIVs and all I see is pretty simple one column forms. I have some pretty complicated forms, here is a picture of one:
http://img835.imageshack.us/img835/8292/formn.jpg
It is easy to make it work with table (which I do), the only problem I have is that sometimes I need to not display some of the choices and move the values up one row to avoid gaps.
I started making some forms using divs, but they fall apart when I change the browser window size and it is not easy to align things.
This topic is helpful:
Is it bad design to use table tags when displaying forms in html?
but it doesn't address some of the concerns I have.
What would you propose as a solution? I can dynamically delete/insert values in the table or try to do the DIVs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会走div路线。只要您在应用浮动时注意宽度,让布局在不同的屏幕分辨率下正常工作实际上非常简单。
以下是一些规则:
至于标记,您可以使用表单元素和 CSS 来创建语义结构:
CSS:
您可以查看结果在这里。
I would go the div route. As long as you're careful of your widths when you apply floats, it's actually pretty straightforward to get the layouts to work properly in different screen resolutions.
Here are a few rules:
As to the markup, you can use the form elements along with CSS to create a semantic structure:
And the CSS:
You can see the result here.
如果是固定宽度的表格,用div和float来布局就很简单了。只需将每个宽度设置为您想要的即可。
对于液体布局表格(液体布局通常是非常理想的),在没有表格样式显示的情况下排列表单要困难得多,因为
float
和position
不容易进行诸如“分配固定宽度标签后,该单元格是父单元格剩余宽度的一半”之类的计算。因此,在这种情况下,当然包括您发布的两列表单,
table-*
CSSdisplay
值是您唯一的可能性。如果您只针对IE8和其他现代浏览器,您可以使用div并在样式表中设置display: table-row
等。但是,为了与 IE6-7 和其他旧版/移动/利基浏览器兼容,您必须使用实际的/
/
< ;td>
元素,因为只有现代浏览器才支持独立于表元素的 table-CSS。这并没有什么可耻的。无论如何,表单是一种半表格,并且不存在实际的可访问性缺点,因为页面内容保持适当的顺序。
注意:对于液体布局表单,您还存在调整输入字段大小以匹配父元素的问题。
输入{宽度:100%; }
几乎做到了,但不完全是,因为width
不包括输入默认情况下获得的边框或填充。您可以使用 CSS3box-sizing
及其特定于浏览器的版本来解决现代浏览器的问题,但如果您希望它也与 IE6-7 上的像素完全对齐,您将需要在父元素上使用的填充等于子输入字段上的边框/填充。If it is a fixed-width table, it's trivial to lay out with divs and floats. Just set each width to exactly what you want.
For a liquid-layout table—and liquid layout is in general highly desirable—it is much harder to arrange a form without table-style-display, because
float
andposition
do not readily allow for calculations like “this cell is half the remaining width of the parent, after the fixed-width labels have been allocated”.So in cases like this, which certainly includes the kind of two-column form you posted, the
table-*
CSSdisplay
values are your only possibility. If you are aiming only at IE8 and the other modern browsers, you can use divs and setdisplay: table-row
et al in the stylesheet. However for compatibility with IE6-7 and other older/mobile/niche browsers, you will have to use actual<table>
/<tr>
/<td>
elements, as only the modern browsers support table-CSS independently of the table-elements.There is no shame in this. A form is kind-of semi-tabular anyway and there is no practical accessibility disadvantage because the page content remains ordered appropriately.
Note: for liquid-layout forms you also have the issue of sizing input fields to match the parent element.
input { width: 100%; }
almost does it, but not quite, because thewidth
is not including the border or padding that inputs get by default. You can use CSS3box-sizing
and the browser-specific versions of it to get around that for modern browsers, but if you want it to line up exactly to the pixel on IE6-7 too you would have to use padding on the parent elements equal to the border/padding on the child input field.一般信息
是某种列表,键>准确地说,值列表 -可能是最好的结构
Issues value
是一个表,Ratings
是一个表,Redemption
和Indicators
都是列表 - 无序列表General information
is some kind of list, key > value list to be exact -<dl />
would be probably the best structure for itIssues values
is a table,Ratings
is a table,Redemption
andIndicators
are lists - unordered lists<ul />