表格中是否包含 HTML 表单
在任何人关闭这个问题或抱怨之前...我一直在整个 StackOverFlow 网站上查找,但找不到任何有关表格和表单的直接信息。
我有一个表单,其中至少有 20 到 35 个不同类别的标签和文本框。因此,开始为每个元素使用 CSS 就太过分了。
出于某种原因,我想使用表格将所有字段与其各自的标签对齐,因为某些标签会比其他标签大(即“名字”比“年龄”更大) ,因此布局会扭曲。我无法开始为每个标签和文本框应用 css(每个标签和文本框大约 20 个......这是 40 个单独的 css 规则)。
除非有人能给我一些技巧,否则我会很感激。
我知道 CSS 对于表单很有用,但是对于非常大的表单呢?
Before anyone close this question or complain... I've been looking all over StackOverFlow site but couldn't find anything straight foward about tables and forms.
I have a form which has at least 20 to 35 labels and text boxes, in different categories. So to start using CSS for each element would be too much.
For some reason, I'm feeling like using tables to align all the fields with their respective labels, since some labels will be larger than others (i.e. 'First Name' is a larger word than 'Age'), and so the layout would be distorted. And I can't start applying css for each label and text box (circa 20 each... that's 40 individual css rules).
Unless someone can give me some techniques, I'll be greatful.
I know CSS is good for forms but what about the very big forms?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
只要您充分利用级联,表单的 CSS 就没有任何问题。
事实上,我推荐它而不是使用
table
。只需设置一些基本规则...
然后处理规则的例外情况...
So long as you use the cascade to your advantage, there is nothing wrong with CSS for forms.
In fact, I recommend it over using
table
.Just set up some base rules...
Then handle the exceptions to your rules...
表单不是表格数据,简单的表单只是表面上看起来像它们。
CSS 适合长格式。具有适用于大多数数据的样式。然后是针对短数据位和/或长数据位的更具体的样式,等等。不要单独设计所有东西。
Forms are not tabular data, simple forms just superficially look like they are.
CSS is just fine for long forms. Have styles for most data. Then more specific styles for short bits of data and/or long bits of data, and so on. Don't style everything individually.
尝试使用 UL 和 LI 而不是表格,如以下文章中所述 点击查看文章
它也提供了CSS。
try using UL and LI instead of table, such as explained in the following article Click to see article
It provides the CSS too.
您不需要 40 个单独的 CSS 规则。您可以为所有标签制定一项规则,为所有文本框制定一项规则。
但是 - 话虽如此 - 这种布局,你有两列内容,并且你希望第 1 列中的所有内容(本例中的标签)彼此对齐,并且第 2 列中的所有内容(文本)框)彼此对齐,同时保持行对齐 - 这正是好桌子所擅长的事情。
我是 CSS 的大力倡导者,并且我相信滥用表格(例如布局页面)是邪恶的、邪恶的、邪恶的 - 但我肯定会选择使用表格。
You wouldn't need 40 individual CSS rules. You could have one rule for all the labels, and one for all text boxes.
BUT - having said that - this sort of layout, where you have two columns of stuff, and you want all the stuff in column 1 (the labels in this example) aligned with each other, and all the stuff in col 2 (the text boxes) aligned with each other, while keeping the rows aligned - well that's exactly the sort of thing that the the good ol' table excels at.
I am a big advocate of CSS, and I believe that abuse of tables (to layout a page for example) is evil, evil, evil - but I would definitely go with tables on this one.
归根结底,这都是关于偏好和功能的。我个人偏好是 div/CSS。 CSS 的级联性质,以及代码的简洁性等等。
但是,嘿,如果你喜欢表格 - 从屋顶上大声喊出来!
At the end of the day, it's all about preference and functionality. My personal preference are divs/CSS. The cascading nature of CSS, and cleanliness of the code, etc..
But hey, if you like tables - shout it from a rooftop!
您可以使用 jQuery Masonry。
据我所知,它会实现你需要的布局,你所要做的就是添加类和一行 JS 代码。
You can use jQuery Masonry.
As far as I can see, it will achieve the layout you need and all you have to do is add classes and single line of JS code.
您可以使用 CSS 创建良好的、可访问的表单,而无需太多 CSS 规则(无论如何,对于对齐部分)。您基本上只需要设置所有标签的宽度(使用一条规则)并定义它们如何与输入元素交互。 http://www.websiteoptimization.com/speed/tweak/forms/< 有一篇不错的文章/a> (只是我发现的第一个,我确信还有很多其他的)。
You can create good, accessible forms using CSS without too many CSS rules (for the alignment part, anyway). You basically just need to set the width of all the labels -- with one rule -- and define how they interact with the input elements. There a nice article at http://www.websiteoptimization.com/speed/tweak/forms/ (just the first one I found, I'm sure there are many others).
对于表格,我宁愿使用更干净的桌子。使用 CSS 进行网站布局。但这又是我的意见...
For a form IMO i'd rather use a table its cleaner. Use CSS for your websites layout. But again thats my opinion...