我必须在现有 <td>
中插入一个复选框和一个字段.但是,这些字段目前未显示在一行中。请在下面找到 html:
<!DOCTYPE html>
<html>
<body>
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>
<p>Timer<p/>
<input type="checkbox" id="checkBox" name="checkBox" size="30"/>
</td>
<td>
Please check the box
<td>
</tr>
</table>
</body>
</html>
输出如下:
Jill Smith
Timer Please check the box
[]
这里“定时器”和复选框不在同一行(在同一个 <td>
内)。
有人可以帮帮我吗?
PS:我无法更改已经可用的表格格式。
p里面有timer的原因:
定时器是一个动态字段,它的计数从 20 开始到 0。
所以我必须使用 <p>
我在这里没有提到的 JavaScript 中的元素 id。
最佳答案
td p,td input{float:left}
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>
<p>Timer<p/>
<input type="checkbox" id="checkBox" name="checkBox" size="30"/>
</td>
<td>
Please check the box
<td>
</tr>
</table>
td p,td input{display:inline}
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>
<p>Timer<p/>
<input type="checkbox" id="checkBox" name="checkBox" size="30"/>
</td>
<td>
Please check the box
<td>
</tr>
</table>
td p,td input{display:inline-block}
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>
<p>Timer<p/>
<input type="checkbox" id="checkBox" name="checkBox" size="30"/>
</td>
<td>
Please check the box
<td>
</tr>
</table>
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>
<p>Timer<input type="checkbox" id="checkBox" name="checkBox" size="30"/><p/>
</td>
<td>
Please check the box
<td>
</tr>
</table>
更新(评论请求)
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>
<p style="float:left">Timer<p/>
<input style="float:left" type="checkbox" id="checkBox" name="checkBox" size="30"/>
</td>
<td>
Please check the box
<td>
</tr>
</table>
添加一个类
.inline{
display:inline
}
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>
<p class=inline>Timer<input class=inline type="checkbox" id="checkBox" name="checkBox" size="30"/><p/>
</td>
<td>
Please check the box
<td>
</tr>
</table>
关于html - 如何在同一列中给出两个html元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26353656/