table td 图片水平垂直居中实现代码

设置img在表格table中的单元格td中水平垂直居中,想必很多的朋友都想实现此效果吧,接下来为大家详细介绍下实现代码,感兴趣的你可不要错过了哈或许对你有所帮助


代码如下:

<td align="center" valign="middle">
<img src="images/checkBox.png"/>
</td>

其中 align="center" 为水平居中 ;
valign="middle" 为垂直居中,这个属性有时不见得好用。
也可以通过样式设置:

Html代码 :

复制代码
代码如下:

<td style="text-align: center;">
<img style="vertical-align:middle;" src="images/checkBox.png"/>
</td> 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
非常抱歉,我刚才理解有误。如果你想在 ant design vue 的 table实现单元格内容的垂直居中,可以通过设置单元格的样式来实现。具体步骤如下: 1. 在 `columns` 中定义需要垂直居中的列,并添加 `customRender` 属性来自定义单元格内容的渲染方式,示例如下: ```html <template> <a-table :columns="columns" :data-source="data" :pagination="false"> </a-table> </template> <script> export default { data() { return { data: [ { key: '1', name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park' }, { key: '2', name: 'Jim Green', age: 42, address: 'London No. 1 Lake Park' }, { key: '3', name: 'Joe Black', age: 32, address: 'Sidney No. 1 Lake Park' }, ], columns: [ { title: '姓名', dataIndex: 'name', customRender: (text, record, index) => { return { children: text, attrs: { style: 'vertical-align: middle;', }, }; }, }, { title: '年龄', dataIndex: 'age', customRender: (text, record, index) => { return { children: text, attrs: { style: 'vertical-align: middle;', }, }; }, }, { title: '地址', dataIndex: 'address', customRender: (text, record, index) => { return { children: text, attrs: { style: 'vertical-align: middle;', }, }; }, }, ], }; }, }; </script> ``` 在上面的示例中,通过在 `customRender` 中返回一个对象,该对象包含 `children` 和 `attrs` 两个属性。其中 `children` 表示单元格的内容,`attrs` 表示单元格的其他属性,例如 `style`。设置 `style` 属性为 `'vertical-align: middle;'` 即可实现单元格内容的垂直居中。 2. 在 `style` 中添加 `table td` 的样式,以覆盖默认样式,示例如下: ```html <template> <a-table :columns="columns" :data-source="data" :pagination="false" style="table td{padding: 16px;}"> </a-table> </template> ``` 在上面的示例中,通过在 `style` 中添加 `table td` 的样式,设置单元格的内边距为 `16px`,以使单元格内容更加美观。 通过上述步骤,就可以在 ant design vue 的 table实现单元格内容的垂直居中了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值