HTML 防止换行(两个表格标签之间)
我有以下代码:
<table>
<tr>
<td>Table 1</td>
</tr>
</table>
<table>
<tr>
<td>Table 2</td>
</tr>
</table>
非常不幸的是,在这两个表之间插入了换行符。我尝试将它们放在一个跨度中并将空白设置为 nowrap,但无济于事。请您告诉我如何简单地将这些元素放在一行中,而无需在 CSS 中设置浮动属性,也不用 包围每个表格。 {table}
,然后将其放入表格行中。
预先非常感谢。我已经问过 Google,但它就是什么也没说 ^^ StackOverflow 到目前为止也保持沉默
I have following code:
<table>
<tr>
<td>Table 1</td>
</tr>
</table>
<table>
<tr>
<td>Table 2</td>
</tr>
</table>
Very unfortunately, a line break is inserted between these two tables. I have tried putting them both in a single span and setting the whitespace to nowrap, but at no avail. Please, could you tell me how I can simply put these elements in a single row, without setting the float attribute in CSS and without surrounding each table with a <td> {table} </td>
and then putting this in a table row.
Thanks a lot in advance. I have asked Google, but it just wouldn't say anything ^^ StackOverflow remained silent so far, too
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我找到了!
必须对两个表使用以下设置:
感谢内联,伙计们,非常感谢,但至少,内联表有效^^
希望我有所帮助......
I found it!
One has to use the following settings for both tables:
Thanks for the inline, guys, thanks a lot, but at least, inline-table works ^^
Hope I helped...
根据CSS盒子模型:
一个快速解决方法是在要分隔的表格顶部添加填充。
According to the CSS box model :
A quick fix is to add padding to the top of the table that you want to separate.
如果将表 1 向左浮动,而将表向右浮动会怎样?默认情况下,表格是“块”元素,因此您可以尝试使用display:inline。
What if you float table 1 to the left, and table to to the right? By default, tables are "block" elements, so you could try display:inline.
或者这个:
or this:
table{display:inline;}
不起作用?table{display:inline;}
didn't work?更新:这个答案非常古老,今天已经存在新的、更好的技术。
原始内容:
您应该为此使用 CSS,因为这是一个表现问题。为什么不能使用CSS?
我就是这样做的。简单,适用于所有浏览器,并且可以轻松适应周围的布局元素。为两个表提供适合其包含元素的宽度,并将它们都向左浮动。例如:
Update: This answer is very old, and new, better techniques exist today.
Original content:
You should use CSS for this, as it is a presentational issue. Why can't you use CSS?
This is how I'd do it. Simple, works in every browser and it easily adapts to surrouding layout elements. Give both tables a width that fits them in the containing element, and float both of them to the left. For example:
试试这个CSS:
或者你可以侵入负上边距
Try this css:
Or you can hack into negative top-margin