What is the reason for parent rows not stretching fully across the width of the page?

I am working on creating a simple table in Vue.js with Bootstrap. When the arrow is clicked, the child row is displayed, and I want it to appear below the parent row. I achieved this by setting

display:flexbox; flex-direction:column;

Here is the HTML table:

<table>
    <thead>
        <tr>
            <th scope="col"></th>
            <th scope="col">ID</th>
             ...
            <th scope="col">Actions</th>
    
        </tr>
    </thead>
    <tbody>
        <tr class="parent" v-for="item in data" :key="item.data.ID">
            <td>
               ...
              </button>
            </td>
            ...
                 <td>{{ item.data['Knows the answer?'] }}</td>
                    ...
                      </button>
                   ...
                </td>
              
            <template v-if="item.children && item.children.has_nemesis && Array.isArray(item.children.has_nemesis.records) && item.children.has_nemesis.records.length && item.childrenVisible">
                ...
                        <td >{{ secret.data['Secrete Code'] }}</td>
                     ...
        
                 
                
                          
                               
                                      
                                          
                                        ...
                                     
                                              
                                                
                                                
                                           
 
        </tbody>
    </table>

However, this layout caused the parent rows not extend full length (see image) https://i.stack.imgur.com/UL2k0.png

Applying CSS:


    table {
        border: 5px solid red !important;
        display: flex;
        flex-direction: column;
    }

    thead{
        border: 5px solid blue;
    }
    
    tbody{
       ...
    }

    .parent{
        ...
    }

    td{
       ...
    }

Visual reference: https://i.stack.imgur.com/gDtwF.png

Answer №1

Avoid using flex in your table. Instead, consider utilizing table-layout: fixed;. Given the complexity of the table structure, assigning an id to the headers and using headers for rows could be beneficial. Here is an example:

<table>
    <thead>
        <tr> 
            <th id="col"></th>
            <th id="id">ID</th>
            <th id="name">Name</th>
            ...
        </tr>
    </thead>
    <tbody>
        <tr class="parent" v-for="item in data" :key="item.data.ID">
            <td headers="col">
                ...
            </td>
            <td headers="id">{{ item.data.ID }}</td>
            <td headers="name">{{ item.data.Name }}</td>
            ...
        </tr>
    </tbody>
</table>

To set column widths uniformly, utilize thead th:nth-child(n). Start by defining the table styles as shown below:

table {
  table-layout: fixed;
  width: 100%;
  border: 1px solid;
  border-collapse: collapse;
}

thead th:nth-child(1) {
  width: 8%;
}
...
th, td {
  padding: 0.5rem;
  border: 1px solid;
}

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

Footer placement not aligning at the bottom using Bootstrap

I'm having trouble getting my footer to stay at the bottom of my website without it sticking when I scroll. I want it to only appear at the bottom as you scroll down the webpage. Currently, the footer is positioned beneath the content on the webpage. ...

Is it possible to use jquery to specifically target classes?

I am trying to achieve the following: $('.class.img').css('cellpadding', variable); However, this code does not seem to be working as expected. Despite searching online, I have not been able to find a solution. Any assistance on how to ...

Having trouble creating a scatter chart using vue-charts library

Whenever I try to render the chart, all I get is a blank page along with this error message: TypeError: Cannot read property 'getBasePixel' of undefined There seems to be an issue with my implementation in Vue.js even though I followed the ex ...

What strategies can be utilized to raise the max-height from the bottom to the top?

I am facing the following coding challenge: <div id = "parent"> <div id = "button"></div> </div> There is also a dynamically generated <div id="list"></div> I have successfully implem ...

Trigger a function on q-select change using onChange event (Quasar Framework)

I'm trying to get the function to run when I change the selected value, but it's not working. How can I solve this issue? Below is the code I am using: <q-select v-model="single" :options="['def', 'abc', ...

Exploring how to replicate background-size: cover with a center position using HTML5's <video> tag

Looking to replicate the effect of background-size: cover on a <video> element. I was able to achieve this with the code below: <video id="videobackground" autoplay="true" loop="true"> <source src="BackgroundFinal2.mp4" type="video/mp4" ...

Tips for locating direct children of a non-root element using CSS selectors in Selenium

When working with a <table> element, I encountered the need to search for its descendants and direct descendants while avoiding wading through nested tables. The elements I seek lack reasonable IDs, so specific selectors are essential: <html> ...

The addClass and removeClass functions in jQuery are functioning properly only on Firefox browser

Could someone help me understand why this code works in Firefox but not in Safari or Chrome? The variable newClass retrieves the value from a select box, which is then used to create a selector for adding or removing classes using addClass/removeClass. I ...

Is there a method to implement a pop-in animated contact form without the use of Javascript or query selectors?

Although I was successful in creating a contact form with this functionality using Javascript, I encountered some difficulties when attempting to achieve the same result without it. My goal is for the form to slide in from the right when the "open" icon is ...

Prevent users from copying and pasting text or right-clicking on the website

I have been struggling to completely disable the ability for users to copy and paste or select text on my website across all devices. After much searching, I came across a solution that I implemented on my site. Below the <body> tag, I inserted the ...

Twitter Bootstrap 3 Carousel now showcasing a pair of images simultaneously instead of three

Can this carousel be configured to show just 2 pictures at a time instead of 3? Check out the live demo here. I've attempted adjusting the columns to col-md-6 and the CSS to 50%, but haven't had any success... ...

IE encounters an absolute z-index problem when expanding concealed content

I'm having trouble with the positioning of a block (div). I am new to CSS, so any help would be greatly appreciated. Here is the code snippet: http://jsfiddle.net/9rEmt/ (please check it out) for viewing online in IE. When I use absolute for positio ...

Personalized Firefox Scrollbar - Rounded Corners

I have successfully customized the default CSS of browser scrollbars for Chrome and Edge, but I am facing issues with Firefox. Is there a way to sync the scrollbar styling in Firefox with Chrome and Edge? Currently, I am unable to apply border radius to th ...

Creating dynamic attribute names in Vue with Pug is a powerful combination that allows

Struggling to figure out the correct method for incorporating dynamic attribute names into a Vue template using Pug. Currently, I have the following setup: <template lang="pug"> button(id=`button__${buttontype}`) slot(name="text&qu ...

The process of increasing value through a function in PHP

Looking to create a function that increments a variable when a button is clicked. I have 4 buttons: farm, cave, house, casino The goal is to accumulate the random numbers generated by each button and add them up in the "YOUR GOLD" section. For example, c ...

Using alphabets or Roman numerals as an index in a Vuejs For loop: A step-by-step guide

In the Vue.js v-for loop, the default iterator starts from 0, 1, 2, 3... But how can we set the v-for to start index with i, ii, iii, or a, b, c instead of numbers? For example, consider the following content: let content = [ "Content1", &quo ...

What is the process for invoking a function from a sibling component upon pressing a button?

Hello, I need some assistance. I have created a calendar that displays events set by the user and now I want to implement a feature where clicking on an event will show detailed information about it. The issue is that the events are in one component while ...

Arrange a div element within another div by utilizing the fixed positioning property, while also accounting for any potential "white space

Can someone help me figure this out: I currently have this much progress: http://jsbin.com/apikiw/3/edit#preview The issue I'm facing is that I am unable to insert it between the <p /> tags due to its dynamic nature... any solutions or suggest ...

What was the reason behind resolving the 0 height body problem by adjusting the WebView Layout Parameter?

My Xamarin WebView was not displaying my HTML correctly. Even though it was set to fill the whole screen, the body height in the HTML remained at 0px. In addition, I had a div in the HTML with the following style: position:absolute; top:0px; bottom:0px; ...

Tutorial on displaying historical pricing data on a chart utilizing props in Vue Chartkick

I recently discovered a chart library called Chartkick for Vue projects. If you're interested, you can check it out here: In my project, I have data passed as props to a component. However, I encountered an issue where the prop couldn't be acces ...