html - 如何覆盖 td align ="center"?

标签 html css html-table

收集自 Why align="center" not overriding on {text-align:right;}在这篇文章中,CSS 应该对旧式布局属性有先见之明。我正在从事一个元素,我必须在具有以下格式的单元格中注入(inject)内容:

<td align="center">...</td>

我不希望我的内容居中,尝试使用 text-align="left"不会覆盖 td-tag,如文章中所建议的那样。我该怎么做才能覆盖 TD 对齐属性?

最佳答案

如果允许更改 td 的内容,则可以将 td 值用另一个带有 text-align:left 的标签包裹起来;

结果标签将是:

<td align="center">
  <div class="left">content here</div>
</td>

这是新的 CSS:

td div.left { text-align:left; }

如果您无法修改单元格值,另一种解决方法是使用 javascript 修改对齐属性,在 jquery 中:

$(document).ready(function(){
   $('td [align=center]').attr('align','left');
   // $('td [align=center]').attr('align','left').css('text-align','left'); //or still not working
});

关于html - 如何覆盖 td align ="center"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3491593/

相关文章:

javascript - 如何在 Handsontable 中创建跨越两列的行标题?

html - 为什么我的页面不会停止缓存?

javascript - 即使我按下退格键/删除键,该功能仍保持事件状态。并在加载页面时获取选择的值

javascript - 如何从复选框元素中获取默认值?

jquery - "Uncaught TypeError: Failed to execute ' getComputedStyle ' on ' 窗口 ': parameter 1 is not of type ' 元素'.Tq ​​@ VM107 :37mF , 当 gmap 添加时

css - 显示内填充 : table-cell extends past container

css - IE 11 使用我的响应式设计

html - 整个标题行充当链接,而不仅仅是文本所在的位置

html - 嵌套的 Bootstrap 表格未填充父单元格高度

html - 表格数据显示不适用于手机和平板设备