对齐文本。使用表格或 CSS 或 ?
我经常对齐文本,例如:
To:07/02/2010
来自: 07/02/2010
我希望它显示如下:
To: 07/02/2010
From: 07/02/2010
那么最快/最简单/最好的方法是什么? CSS?使用一些nbsp(如果是单间距就可以)或使用表格。通常,如果我没有反讨厌桌子的心情,我就会使用桌子。
你有什么建议吗?
Frequently I am aligning text such as:
To: 07/02/2010
From: 07/02/2010
Id like it to be displayed like this:
To: 07/02/2010
From: 07/02/2010
So what is the quickest/easiest/best way to do this? CSS? using a few nbsp (would work if its mono spacing) or using tables. Normally if I am not in a anti-hating table mood, ill use tables.
What do you recommend?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
绝对定义列表 (
)。
Definitely definition list (
<dl>
).我会推荐桌子。这确实是最好的方法,特别是因为它确实是表格数据,并且 HTML 不支持制表位。
但为了避开桌子而避开桌子确实很愚蠢。除非您希望稍后的选项像这样设置样式:
如果由于某种原因您不想使用表格,您可以这样做:
CSS
HTML
或者使用定义列表(但如果您避免表的原因是由于语义,那么对于同一件事将避免 DL)。
但当然,这是关于布局的,没有客户或网络冲浪者会关心你是如何做的,只要他们能读懂它!
I'd recommend tables. It really is the best way, especially seeing as it really is tabular data there, and HTML doesn't support tab stops.
But it really is silly to avoid tables for the sake of avoiding tables. Unless you want the option later to style like so:
You could do something like this, if for some reason you didn't want to use tables:
CSS
HTML
Or use a definition list (but if the reason you are avoiding tables is due to semantics, then DLs would be avoided for the same thing).
But of course, it's about the layout, no customer or web surfer is ever going to care how you do it, as long as they can read it!
使用定义列表或空格 nowrap。
Use a definition list or white-space nowrap.
我以前见过这个问题,快速谷歌搜索:
http://www.google .com/search?q=css+forms
...把我带到这里:
http://www.webcredible.co.uk/user-Friendly-resources/css/css-forms.shtml
...我将 HTML 和 CSS 复制粘贴到此:
我觉得不错,将其保存为 .html 并亲自查看。
I've seen this problem before, a quick google search:
http://www.google.com/search?q=css+forms
...brought me here:
http://www.webcredible.co.uk/user-friendly-resources/css/css-forms.shtml
...and I copypasted the HTML and CSS into this:
Looks good to me, save it in a .html and see for yourself.
使用
s 进行填充听起来很混乱。像这样的事情怎么样:
不过,在这种情况下,我实际上会说表格是合适的;它看起来确实像表格数据,带有一列标题。
Padding with
s sounds messy. How about something like this:
In this case, though, I'd actually say tables are appropriate; it does look like tabular data, with a column of headers.
这在工作中出现过很多次,我最终为隐藏边框的 2 列表创建了一些样式。 技术上,这是表格数据,但考虑到在规范内实现它所需的标记量,只有 2 行和 2 列的表格相当蹩脚。
我经常后悔创建这个类,因为现在每个人都使用它太多了,我必须在代码审查中不断地寻找它。如果您没有预见到这个问题,那么这是一个语义上正确的解决方案,并且比您使用 DL、跨度等跳过的麻烦稍微优雅一些。
This has come up at work many times and I ended up creating some styling for a 2-column table which hides borders. Technically, this is tabular data, but a table with only 2 rows and 2 columns is pretty lame considering the amount of markup needed to achieve it within spec.
I've often regretted creating the class, as now everyone uses it far too much and I have to constantly be on the lookout for it in our code reviews. If you don't anticipate that problem, it's a semantically-correct solution, and slightly more elegant than the hoops you'll jump through with DL's, spans, etc.