Is there a way to truncate text in a cell using CSS without it wrapping around or overflowing? The ideal CSS code should include:
.truncate {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
However, the current implementation causes the cell to consume all available space:
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="53355c5d4723677d2b">[email protected]</a>/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4a0a3b3a2bfd2ac85e7fbad">[email protected]</a>/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<style>
.truncate {
display: inline-block;
/* width: 200px; */
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<div id="app">
<v-app>
<v-content>
<v-data-table :headers="headers" :items="items">
<template v-slot:item.name="{ item }">
<span class="truncate">{{ item.name}}</span>
</template>
</v-data-table>
</v-content>
</v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8afcffefcab8a4f2">[email protected]</a>/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f98f8c9c8d909f80b9cbd781">[email protected]</a>/dist/vuetify.js"></script>
<script>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: {
headers: [
{ text: 'Name', value: 'name', width: "75%" },
{ text: 'Calories', value: 'calories', width: "25%" },
],
items: [
{ name: 'Frozen Yogurt', calories: 159, },
{ name: 'Ice cream sandwich with a really, really, really long name that keeps going on and on and on forever so there is no space left', calories: 237, },
{ name: 'Eclair', calories: 262, },
], }
})
</script>
</body>
</html>
A fixed pixel width can achieve the desired effect, but I prefer the table and columns to be responsive.