Tips for specifying a constant width for a column in a Vuetify HTML table

I am currently utilizing a Vuetify table and I have a requirement to set fixed column widths based on a specific configuration. My initial approach was to directly assign the width from the configuration to the width CSS attribute.

In the first instance ( Playground ) should show a table with a total width of 350px. Upon reviewing the playground, it appears that the table is occupying the full screen width instead.

<template>
  <v-table>
    <thead>
      <tr>
        <th style="width: 300px">Col 1</th>
        <th style="width: 50px">Col 2</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Item 1</td>
        <td>Item 2</td>
      </tr>
    </tbody>
  </v-table>
</template>

The second scenario ( Playground ) is expected to display a table with a total width of 6300px. The intention is for the first column to be wider than the screen, resulting in a horizontal scrollbar. However, the table automatically adjusts the width of the first column to fit the screen width.

<template>
  <v-table>
    <thead>
      <tr>
        <th style="width: 6000px">Col 1</th>
        <th style="width: 300px">Col 2</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Item 1</td>
        <td>Item 2</td>
      </tr>
    </tbody>
  </v-table>
</template>

I'm looking for a solution to disable this default behavior. The table should adhere to exact column widths as determined by the configuration values. Some attempts made include:

  • <v-table style="min-width: none; max-width: none">
    - No changes observed
  • <v-table style="overflow: auto">
    - No visible alterations
  • <v-table style="width: max-content">
    - Works when table is smaller than screen size, preventing scrollbar appearance
  • <v-table style="width: min-content">
    - Results in a table too small
  • <v-table style="width: auto">
    - No discernible adjustments

Despite these attempted solutions, the issue persists. Any suggestions or alternative ideas to rectify this problem?

Answer №1

To accomplish this task, CSS can be utilized. Begin by applying the following CSS to the <table> tag:

.v-table__wrapper table {
  table-layout: fixed;
  width: 0 !important;
}

MODIFY:

Based on the new example provided in the comment involving colspan and rowspan, it is essential to explicitly set all fixed widths.

here is the updated demonstration

Prior answer: Subsequently, you can specify column widths utilizing the nth-child() CSS selector:

.v-table__wrapper table th:nth-child(1),
.v-table__wrapper table td:nth-child(1) {
  width: 300px;
}

.v-table__wrapper table th:nth-child(2),
.v-table__wrapper table td:nth-child(2) {
  width: 50px;
}

here is the functional demo in playground

Answer №2

To meet this specific need, you can easily adjust the styles for both the table and row elements.

Current Default Styles :

.v-table > .v-table__wrapper > table {
  width: 100%;
  border-spacing: 0;
}

New Style to Fulfill the Requirement :

.v-table > .v-table__wrapper > table {
  width: 0;
  border-spacing: 0;
  table-layout: fixed;
  text-wrap: nowrap;
}

.v-table__wrapper > table > tbody > tr > td {
  overflow: auto;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am interested in layering two divs on top of each other, similar to the

This is a basic code snippet created using HTML and CSS. How can I achieve the effect of overlapping the green div on top of the white div? I have attempted to move the green div up, but increasing the margin-bottom value does not work. #d3{ background ...

Implementing CSS styles on selected elements using jQuery

My current HTML layout looks like this.. <div class="container> <div class="panel"> <div> <div> <div> <img class="match" src="myimage.jpg"> &l ...

Animate the jQuery: Move the image up and down inside a smaller height container with hidden overflow

Check out the fiddle to see the animation in action! The image is programmed to ascend until its bottom aligns with the bottom of the div, and then descend until its top aligns with the top edge of its parent div, revealing the image in the process. ...

Tips for comparing two attributes using Simple HTML DOM libraries

I'm attempting to retrieve a very specific tag using Simple HTML DOM, and I need to check two attributes in order to do this. However, I am unsure of the correct syntax. Currently, my code looks like this: foreach($html->find("ul[class=someclass]" ...

Even with a highly lenient Content Security Policy in place, I continue to encounter violation errors

I currently have this meta tag in my HTML document: <meta http-equiv="Content-Security-Policy" content="default-src *;script-src *"> My project uses ParcelJS as a bundler. Everything works smoothly when using the development serv ...

Is it just me or is one of these pieces of javascript not functioning properly?

I set out to develop a checklist that would automatically adjust a slider as users interacted with checkboxes. After some research, I stumbled upon the following two code snippets: http://jsfiddle.net/t2nvft7q/ $(document).on('click', '.ch ...

What could be causing the failure in revealing these elements?

Within my Meteor application, I utilize Template.dynamic to seamlessly replace the current Template with the next one. In my "main" html file, the setup looks like this: <div class="container"> {{> postTravelWizard}} </div> </body> ...

Switch up the order of columns by utilizing the push and pull features of Bootstrap

My layout consists of 3 columns arranged like this: <div class="container-fluid"> <h1>Hello World!</h1> <p>Resize the browser window to see the effect.</p> <div class="row"> <div class="col-sm-3">left co ...

What is the process for generating an auto-incrementing button with a *different input field*?

After searching everywhere for a code snippet to add another input bootstrap input group, I finally decided to take matters into my own hands and create one from scratch. And would you believe it worked like a charm! ...

disabling empty elements in a React JS JavaScript component

Currently, I am retrieving data from an API where users can post content up to 3 times. However, if a user has not posted three times, empty boxes with padding and background color will appear. I want to remove all elements that do not have any content wit ...

Expanding Bootstrap 5 dropdown menu dynamically using Javascript

Is there a method to achieve this goal? I am currently attempting to implement a dropdown menu that dynamically populates with year numbers starting from the current year. Unfortunately, the solutions I have come across only work with native HTML and not B ...

Enhancing the appearance of a dropdown menu in HTML

Hello, I am looking to customize the appearance of a dropdown menu in HTML, specifically focusing on the option tags. While Firefox displays the desired style, Internet Explorer and Google Chrome are not rendering it correctly. Currently, the padding only ...

Tips for resizing images to have uniform dimensions

I am trying to create an image gallery where all the images are uniform in size. Currently, I am referencing this tutorial for guidance on my CSS. div.gallery { border: 1px solid #ccc; } div.gallery:hover { border: 1px solid #777; } div.gallery img ...

What is the best way to ensure that a piece of content remains stationary while the neighboring content shifts in position?

Hello there! I'm currently working on my very first HTML and CSS project, and one of the tasks involves aligning 4 icons side by side horizontally. The goal is to have the icons "grow" a bit when the mouse hovers over them. However, I've encounte ...

Unable to get CSS Filter to function properly in Firefox

I'm having trouble with the CSS filter on my Firefox (15.0) browser. Here is the HTML code: <div class="google"> <img src="https://www.google.com/images/srpr/logo3w.png"> </div> And here is the CSS code: .google{ -moz ...

Guide to showing user input upon button click using Vue?

I've been researching text fields but I'm having trouble understanding it.. I'd like to input a name and age, and then after clicking the "add" button, I want to see the name and age displayed below. What is the most efficient or optimal way ...

Get rid of emojis and unicode characters

My website and database are both configured to utf-8 and utf8mb4 encoding. While textareas accept utf-8 symbols and emojis without issue, I want to restrict certain input fields (such as name and address) to only allow basic text and numbers. This include ...

What is the best way to align the navigation menu in the center?

<nav> <a href="/C:\Users\Emily O\Documents\WebDevelopment\JamminJava/index.html">Home</a> | <a href="/C:\Users\Emily O\Documents\WebDevelopment\JamminJava/menu.html">Menu</a> | ...

Utilizing React Bootstrap with TypeScript for Styling Active NavItem with Inline CSS

Is it possible to change the background color of the active NavItem element to green using inline CSS in React Bootstrap and React Router Dom? I am currently using TypeScript 2.2 and React. If not, should I create a CSS class instead? Here is the code sni ...

Tips for implementing the "AddThis" button on Joomla

I recently installed the AddThis for Joomla! module on my Joomla website. However, I am facing an issue where I cannot get it to float to the left side of the screen like I see on other sites. On some websites, the AddThis button remains in place even when ...