The columns in the table are all displaying varying widths even though they have been defined with fixed table layout

I have a nested table displayed in my HTML, and I am attempting to set each column to be 50% width, but for some reason it's not working.

In the past, whenever I've needed to accomplish this, applying table-layout: fixed has usually done the trick. However, this time it doesn't seem to be effective.

What could be going wrong? Check out the editor link here

<table class="employment" *ngFor="let item of empTabData| slice:1">
                <div class="container" fxLayout="row " fxLayout.xs="column">
                    <div class="item-1 " fxFlex="50%" fxFlex.xs="100%">
                        <tr *ngFor="let i of item.employerInfo | slice:0:(item.employerInfo.length/2)+1">
                            <td class="emp">
                                {{i.key}}
                            </td>
                            <td class="emp">
                                {{i.value}}
                            </td>
                        </tr>
                    </div>
                    <div class="item-1" fxFlex="50%" fxFlex.xs="100% ">
                        <tr *ngFor="let i of item.employerInfo | slice:(item.employerInfo.length/2)+1:item.employerInfo.length">
                            <td class="emp">
                                {{i.key}}
                            </td>
                            <td class="emp">
                                {{i.value}}
                            </td>
                        </tr>
                    </div>
                </div>

            </table>

p {
  font-family: Lato;
}
.employment {
  border-collapse: collapse;
  width: 100%;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  transition: 0.3s;
  font-family: 'Roboto', 'Helvetica Neue', sans-serif;
  font-size: 12px;
  font-weight: 500;
  margin: 1%;
  white-space: nowrap;
}
.employment tr:nth-child(even) {
 background: #fafafa;
}

.emp {
   width: 50%;
   white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


export class AppComponent  {
empTabData =  [{"employerInfo":[{"key":"UAN","value":"100460235222"}]},{"employerInfo":[{"key":"Matched Name","value":"UAT Test Aadhaar Name"},{"key":"User Id","value":"442ad831-983f-44ca-ac7f-e1851c911fb3"},{"key":"ID","value":"PYBOM00250170000001586"},{"key":"Employer","value":"EMIDS TECHNOLOGIES PVT LTD"},{"key":"Settled","value":"true"}]},{"employerInfo":[{"key":"Matched Name","value":"UAT Test Aadhaar Name"},{"key":"User Id","value":"442ad831-983f-44ca-ac7f-e1851c911fb3"},{"key":"ID","value":"PYKRP17189390000010001"},{"key":"Employer"},{"key":"Settled","value":"false"}]}]
}

Answer №1

The display property for your tbody element is not defined, and it is not taking up the full width of 100%. To address this issue, you can use the following CSS:

tbody {
    width: 100%;
    display: table;
}

}

Answer №2

Changing to table-layout: fixed; resolved the issue for me

tbody{
  width: 100%;
  display:table;
  table-layout: fixed;
}
p {
  font-family: Lato;
}
.employment {
  border-collapse: collapse;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  transition: 0.3s;
  font-family: 'Roboto', 'Helvetica Neue', sans-serif;
  font-size: 12px;
  font-weight: 500;
  margin: 1%;
}
.employment tr:nth-child(even) {
 background: #fafafa;
}

.emp {
   width: 50%;
   white-space: nowrap;
   overflow: hidden;
   text-overflow: ellipsis;
}

https://i.stack.imgur.com/uz0na.png

I hope this solution works for you too! :)

Answer №3

When working with tables in HTML, it's important to remember that you can't place a <div> directly within a <table>. If you're looking for guidance on creating tables, this resource may be helpful: . Instead, consider structuring your table like the following example:

<table class="employment" *ngFor="let item of empTabData| slice:1">   
    <tr *ngFor="let i of item.employerInfo | slice:0:(item.employerInfo.length/2)+1">
        <td class="emp">
            {{i.key}}
        </td>
        <td class="emp">
            {{i.value}}
        </td>
    </tr>

    <tr *ngFor="let i of item.employerInfo | slice:(item.employerInfo.length/2)+1:item.employerInfo.length">
        <td class="emp">
            {{i.key}}
        </td>
        <td class="emp">
            {{i.value}}
        </td>
    </tr>
</table>

If you remove unnecessary divs, such as in the example provided, you can achieve a 50% size for td.emp elements when there is enough space available.

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

pressing the switch will adjust the size of the container

I am looking to implement a feature where clicking on an icon will resize a div to full screen in the browser. Below is the HTML code I have set up for this functionality, and I am open to suggestions on how to achieve this. <div> <a (click)= ...

The Android Webview is experiencing difficulties with loading CSS styles and displaying the blockquote font color effect

I am facing an issue with loading HTML content in CSS through Android WebView. Despite having the code executed, I don't see any observable changes in font color for the text inside blockquote tags Here is the HTML code: <html> <head> ...

Angular 7 ng-select validation with required form control

Currently, I am utilizing the ng-select plugin for a dropdown search feature, but I am encountering issues with validation when a selection is not made from the dropdown menu. Here is how I have implemented it: <div class="form-group"> <ng-sel ...

Running frontend and backend applications together in a Docker container

As I work on integrating my frontend in Angular with the corresponding backend in Spring Boot, both as standalone projects, I am now looking to transition them into production mode. This has led me to consider hosting each project in separate docker contai ...

Showing a 2D array in HTML using ngFor loop

I need to display a list of arrays in an HTML p-table. Here is the array list: [Array(2), Array(2), Array(2), Array(2), Array(1)] 0: (2) ["abc", "def"] 1: (2) ["ghi", "jkl"] 2: (2) ["mno", "pqr"] ...

The scrolling feature is not working in NativeScript's ScrollView component

As I delve into using NativeScript with Angular to develop my debut mobile application, things have been going quite smoothly. However, a recent snag has halted my progress - the page refuses to scroll to reveal its entire content. To showcase this issue, ...

establishing the dimensions of table data cells

I'm facing a challenge with setting the width and height for table data that changes dynamically based on different values. The dimensions of the table itself are not definite, so I need to find a solution. Here's the code snippet I'm curren ...

Enhancing visual aesthetics with Vuetify on v-slot label components

I am working with Vuetify code that appears like this <v-radio-group v-model="gender" column class="radio-group-full-width"> <v-radio value="Boy"> <template v-slot:label> <v-textarea v-model="answer" v-vali ...

Font sizes may vary depending on whether the site is accessed with or without the "www" prefix

There is an odd occurrence on my website where the font size seems to change when viewing both the www version and non-www version. While setting up a 301 redirect is a common solution, I am intrigued by why this discrepancy exists as it is not something ...

Exploring Angular and Typescript - attempting to adjust cursor position for multiple child elements within a contenteditable div despite researching numerous articles on the topic

I could use some assistance in resolving this issue. Here is the stackblitz code I am currently working with If you have any workarounds, please share them with me. The caret/cursor keeps moving to the starting position and types backward. Can anyone hel ...

Why are the items I have inserted inside my <div> tag not appearing on the screen?

What could be simpler than this: {this.state.dash ? <div className='dashWrapper slide'> HELLO </div> : null} I've tried everything, but nothing seems to show up inside the div. ...

What is the overlay feature in Material-UI dialogs?

I recently started using the React-Redux Material-UI package found at http://www.material-ui.com/#/components/dialog My goal is to implement a grey overlay that blankets the entire dialog element, complete with a circular loading indicator after the user ...

Error occurred during the file watch process in PhpStorm after saving the CSSO file

Following the advice in the official PhpStorm documentation, I have implemented a CSS minifier. However, upon attempting to use it, I encountered the following error: cmd.exe /D /C call C:\Users\douglas\AppData\Roaming\npm\css ...

What is causing the button to prevent file selection?

What's causing the button to not allow file selection when clicked on? Interestingly, placing a span or div in the label enables file selection upon clicking them, but not with the button. <html> <body> <label> <input t ...

I would like to add an underline below the title

.thumb-text { position: absolute; width: fit-content; left: 50%; transform: translateX(-50%); } .thumb-text h3 { font-family: Georgia; font-size: 30px; color: black; font-weight: 900; } .thumb-text h3::after { content: ''; p ...

Keep an ear out for upcoming occasions once the transition has been completed

I am looking to create a smooth transition effect that will push the main content downwards when the Twitter Bootstrap collapse menu is activated using the toggle button. However, I have noticed an issue where if I quickly double click the toggle button, ...

angular reactive form: communicate between child and parent components

Having trouble passing values from a child component to its parent in Angular's reactive forms. Any advice? Here is an example of the parent form: <div class="fields-wrap" [formGroup]="parent"> <div class="input-wrap"> <child-compon ...

What is the best way to arrange items by utilizing the Array index in JavaScript?

Currently, I am attempting to make the elements within this angular component cascade upon loading. The goal is to have them appear in a specific layout as shown in the accompanying image. I'm seeking guidance on how to write a function in the TypeSc ...

What are the steps to increase the size of the search bar?

I have been working on this code, but I am struggling to align the search bar properly within the navigation bar. Can someone please guide me on how to achieve this? I apologize for my lack of coding expertise, as I am new to Information Technology and s ...

The color of the left arrow on the tooltip cannot be altered

Currently, I am using a tooltip that is positioned on the right side: <i class="fas fa-question-circle text-blue" data-toggle="tooltip" data-placement="right" title="hello" ></i> I have attempted to modify the color of the too ...