html - td 中的 CSS 样式复选框

标签 html css

我想将表格内的复选框设置为中间/居中

我使用的肮脏方式是

<td>
    <input type="checkbox" style="text-align:center;" ng-model="x.dedbuffer">
</td>

但是,我正在寻找一种方法,使表格内的所有复选框都居中。所以我想出了一个 css

.table td input[type="checkbox"] {
    text-align: center;
}

但是 css 没有按预期工作。如何在 css 中设置样式?

最佳答案

input 的父级上设置它,在本例中为 td

更新了仅针对特定单元格时显示操作方法

table td {
    text-align: center;
}

table {
  width: 300px;
}
table td {
  border: 1px solid;
}
table td.centered {
  text-align: center;
}
<table>
  <tr>
    <td class="centered">
      <input type="checkbox" style="text-align:center;" ng-model="x.dedbuffer">
    </td>

    <td>
      Not centered
    </td>
  </tr>
</table>

如果同一单元格中有更多内容,请添加一个包装器

table {
  width: 300px;
}
table td {
  border: 1px solid;
  text-align: center;
}
table td div {
  text-align: left;
}
<table>
  <tr>
    <td>
      
      <input type="checkbox" style="text-align:center;" ng-model="x.dedbuffer">

      <div>
        Not centered
      </div>

    </td>
  </tr>
</table>

关于html - td 中的 CSS 样式复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37873256/

相关文章:

css - Firefox 条件注释 CSS

html - 重叠粘性标题的问题(重叠其下方的主要内容)

javascript - 在 Javascript 中动态显示长度作为类型

javascript - Html, CSS, php 隐藏一个div

html - 我将如何修改 <div> 元素以同时在网页上居中并保持其大小属性?

html - 为什么我的媒体查询不起作用?

html - 裁剪出css图片容器

javascript - 我的点击事件不工作 我没有收到任何错误 他们只是不工作

php - 如何在php中追加文本

html - 在表格单元格 div 中打断单词