You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Vuetify v-data-table指定列内容垂直居中?

How to Vertically Center Align the ID Column in Vuetify v-data-table?

Got it! Let's fix that vertical alignment for your ID column in Vuetify's v-data-table. There are a couple of straightforward ways to do this:

Method 1: Use Vuetify's Built-in Flex Classes

Vuetify comes with handy flex utility classes that make alignment easy. Just wrap your ID column content in a container and apply the right classes:

<v-data-table :headers="headers" :items="tableData" :items-per-page="5" class="elevation-1">
  <template v-slot:item.id="{ item }">
    <!-- Wrap content in a div with flex alignment classes -->
    <div class="d-flex align-center" style="height: 100%;">
      {{ item.id }}
    </div>
  </template>
</v-data-table>
  • d-flex turns the div into a flex container
  • align-center centers the content vertically within the container
  • height: 100% ensures the div takes up the full height of the table cell, so the alignment works properly across all row heights

Method 2: Custom CSS for Targeted Alignment

If you prefer a more global approach or need to avoid extra markup, you can target the ID column directly with CSS:

First, add a custom class to your data table:

<v-data-table 
  :headers="headers" 
  :items="tableData" 
  :items-per-page="5" 
  class="elevation-1 custom-id-table"
>
  <template v-slot:item.id="{ item }">
    {{ item.id }}
  </template>
</v-data-table>

Then add this CSS (either in your component's <style> tag or global stylesheet):

/* Target the ID column specifically using its column identifier */
.custom-id-table .v-data-table__cell[data-table-column-id="id"] {
  display: flex;
  align-items: center;
  height: 100%;
}

This method is more robust if you might reorder columns later—since it targets the column by its id value instead of its position, it'll keep working even if the ID column moves.

内容的提问来源于stack exchange,提问作者farahm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 18:52:39