【发布时间】:2019-08-04 10:09:33
【问题描述】:
我有几个div 元素,其中每个div 中的某些段落(p)之间有一个table,使用以下代码:
<p style="display: inline-block;">
Something BEFORE the table
<table style="display: inline-block;">
<thead>
<tr>
<th>header</th>
</tr>
</thead>
<tbody>
<tr>
<td>data</td>
</tr>
</tbody>
</table>
Something AFTER the table
</p>
这会产生一个看起来像这样的漂亮内容:
head
Something BEFORE the table Something AFTER the table
data
但是在每个div 之前和之后都有不同的内容长度 table 使其看起来像这样:
head
Something BEFORE the table Something AFTER the table
data
head
Short BEFORE the table Short AFTER the table
data
head
Something long BEFORE the table Something long AFTER the table
data
我想要的是为每个 table 设置一些“边距”,以便它们与父元素的开头有一定的距离(在这种情况下为 p),因此希望看起来像这样:
head
Something BEFORE the table Something AFTER the table
data
head
Short BEFORE the table Short AFTER the table
data
head
Something long BEFORE the table Something long AFTER the table
data
页面的 BEFORE、table 和 AFTER 元素必须像这样处理,因为将这些元素中的每一个都放在自己的 div 上并将它们并排显示会混淆此页面部分的样式,并且还会产生类似的问题,但现在是垂直的(但是如果您的解决方案需要这样做,请分享...也许我最终会使用它)。
P.D:如果您的解决方案包含 Bootstrap,请使用版本 3。
P.D.2:我很抱歉这些例子看起来很乱,我还在习惯这个。
【问题讨论】:
-
旁注:你shouldn't将表格放在p标签内。
-
如果您已经在使用表格来存储数据,只需在前面添加一列用于前面的文本,在后面添加一列用于后面的文本。您想要的效果正是单个表的行为。将所有内容放在一个表格中并完成。
标签: html css twitter-bootstrap-3