html - 如何在同一列中给出两个html元素?

标签 html css html-table

我必须在现有 <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/

相关文章:

html - 单个元素的div容器是什么意思?

jquery - 在可滚动的 div 中垂直滚动绝对定位的表头 (th)

html - 链接在表中不起作用

css - 使用图像而不是 Bootstrap 的字形图标

html - 定位在页眉内 (CSS)

javascript - 具有固定标题且主体上无滚动的 Bootstrap 表

html - 不可能的 HTML 表格

html - 包含特定输入元素的特定 div 类元素的样式

html - 如何在 React 组件上设置自定义有效性?

html - 如何让 CSS repeat-y 在动态高度上重复?