html - 表格单元格中的输入和标签对齐

标签 html css html-table vertical-alignment

如何在表格单元格中垂直和水平居中对齐 labelinput

请帮忙。谢谢。

现在看来

now

它应该是什么样子

must be

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
	<style type="text/css">
		table {
			width: 200px;
			height: 200px;
			background-color: blue;
			text-align: center;
			vertical-align: middle;
		}

		td {
			background-color: yellow;
		}

		input {
			width: 50px;
			height: 50px;
		}

		label {
			display: inline-block;
			line-height: 50px;
		}
	</style>
	<table>
		
		<tr>
					
			<td>
				<input type="checkbox" name="" id="c1">
				<label for="c1">FFFF</label>
			</td>
		</tr>
	</table>
</body>
</html>

最佳答案

inputlabel 上设置的

vertical-align: middle 将正确居中。

我还删除了一些不需要的属性,例如 line-height

<!DOCTYPE html>
<html>

<head>
  <title></title>
</head>

<body>
  <style type="text/css">
    table {
      width: 200px;
      height: 200px;
      background-color: blue;
      text-align: center;
    }
    
    td {
      background-color: yellow;
    }
    
    input {
      width: 50px;
      height: 50px;
      vertical-align: middle;
    }
    
    label {
      vertical-align: middle;
    }
  </style>
  <table>

    <tr>

      <td>
        <input type="checkbox" name="" id="c1">
        <label for="c1">FFFF</label>
      </td>
    </tr>
  </table>
</body>

</html>

关于html - 表格单元格中的输入和标签对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43562033/

相关文章:

html - Bootstrap 与 form-inline in row 右对齐

javascript - _blank 目标表单在 chrome 和 IE 中循环提交

javascript - NodeJS 作为 Google Polymer 1.0 的后端

html - 按钮后的 CSS 怪异破折号

sorting - 分页和排序问题

javascript - 在页面完全呈现之前将 CSS 样式从 chrome 扩展应用到页面 'instantly'

html - 我的 div 图片无法定位。也不将自己放在 0px 顶部和左侧

html - 注入(inject) Ruby 并放入 HTML

javascript - 如何判断您当前是否在 HTML 表格的最后一行?

html - Firefox 17.0.1 忽略字体粗细