Struggling to position table correctly in Angular 2 - excess white space appearing on the right side

I am currently working on creating a table in Angular 2 with 4 columns. However, I have encountered an issue where unwanted white space appears to the right of the last column. Bootstrap is being utilized as well.

Below is the HTML code snippet:

    <div class="panel panel-default">
        <div class="panel-heading">User information</div>
        <div class = 'data-table'>
        <table style="width:60px" class="text-center" header-class="'text-center'" class="table table-bordered"  [mfData]="data" #mf="mfDataTable" [mfRowsOnPage]="10">
            <thead>
            <tr>
                <th style="width: 10%"></th>
                <th style="width: 10%">
                    <mfDefaultSorter by="name">Name</mfDefaultSorter>
                </th>
                <th style="width: 10%">
                    <mfDefaultSorter by="email">Email</mfDefaultSorter>
                </th>
                <th style="width: 10%">
                    <mfDefaultSorter by="age">Age</mfDefaultSorter>
                </th>
                <th style="width: 10%">
                    <mfDefaultSorter by="city">City</mfDefaultSorter>
                </th>
            </tr>
            </thead>
            <tbody>
            <tr *ngFor="let item of mf.data">
                <td>
                  <button class="btn btn-danger" title="remove">
                    <span class="glyphicon glyphicon-remove"></span>
                  </button>
                </td>
                <td>"AJ"</td>
                <td>"AJ"</td>
                <td class="text-right">"AJ"</td>
                <td>"AJ"</td>
            </tr>
            </tbody>
            <tfoot>
            <tr>
                <td colspan="3">
                    <mfBootstrapPaginator [rowsOnPageSet]="[5,10,15]"></mfBootstrapPaginator>
                </td>
            </tr>
            </tfoot>
        </table>
        </div>
    </div>

You can view the screenshot of the page here: https://i.sstatic.net/hH8AT.png

In the screenshot, I have highlighted the white space to the right and a small column-like space at the bottom in yellow. How can I remove these to achieve a proper table layout?

Answer №1

Ensure each <th> cell has a 20% width instead of 10%, and set the table width to 100% for better display.

<div class="panel panel-default">
    <div class="panel-heading">User information</div>
    <div class='data-table'>
        <table style="width:100%" class="text-center" header-class="'text-center'" class="table table-bordered" [mfData]="data" #mf="mfDataTable" [mfRowsOnPage]="10">
            <thead>
                <tr>
                    <th style="width: 20%"></th>
                    <th style="width: 20%">
                        <mfDefaultSorter by="name">Name</mfDefaultSorter>
                    </th>
                    <th style="width: 20%">
                        <mfDefaultSorter by="email">Email</mfDefaultSorter>
                    </th>
                    <th style="width: 20%">
                        <mfDefaultSorter by="age">Age</mfDefaultSorter>
                    </th>
                    <th style="width: 20%">
                        <mfDefaultSorter by="city">City</mfDefaultSorter>
                    </th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <td colspan="3">
                        <mfBootstrapPaginator [rowsOnPageSet]="[5,10,15]"></mfBootstrapPaginator>
                    </td>
                </tr>
            </tfoot>
            <tbody>
                <tr *ngFor="let item of mf.data">
                    <td>
                        <button class="btn btn-danger" title="remove">
                            <span class="glyphicon glyphicon-remove"></span>
                        </button>
                    </td>
                    <td>"AJ"</td>
                    <td>"AJ"</td>
                    <td class="text-right">"AJ"</td>
                    <td>"AJ"</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

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

Is it possible to simultaneously run multiple functions with event listeners on a canvas?

I'm attempting to create a canvas function that displays the real-time mouse cursor location within the canvas and, upon clicking, should draw a circle. I came across this code snippet that reveals the x and y coordinates of the mouse: document.addEve ...

Creating a new line in the content of a MatDialog in Angular 7

I have a situation where I am using MatDialog and attempting to insert a new line in the content definition. I've tried using both \n and </b>, but neither of them seem to work. Is there an alternative way to achieve this without manually e ...

I designed a dropdown menu with a searchable <mat-select> feature, where selecting an item is automatic when a space bar is pressed in the search box

Description : I have implemented a dropdown list using element that contains a list of items along with a search field. This allows users to easily search for specific items in the list instead of manually scrolling through a long dropdown menu. They can ...

Scrollbar not appearing when overflow-y is set in React Textarea Input on Chrome or Edge

I've been struggling to add a scrollbar to a React Textarea. I've referred to an old post on Stack Overflow here and a few other resources, but haven't had any luck. I've tested it in both Chrome (Version 113.0.5672.129) and Edge (Vers ...

Is it considered good practice to utilize Vue.js for managing global shared state and implementing for loops outside of components?

Just getting started with Vue.JS and experimenting with creating two lists of books (read and unread) from a shared object in the global data state. This is my approach - working demo (works like a charm! However, I'm wondering if this is considered ...

Implementing a custom overwrite function in TypeScript's inheritance

Below is a class that I have: export class RestService { private baseUrl: string; constructor(protected http: HttpClient) { this.baseUrl = environment.LOCAL_URL; } public get<T>(resource: string, params?: HttpParams): Observable< ...

What is the best way to align two buttons on the same line if they are positioned outside of an Edit form

Struggling with my Blazor app on .NET Core 7 - I can't seem to get two buttons to display on the same line. The first button needs to be inside an edit form for submitting and inserting data, while the second button should be outside the edit form f ...

The hover feature in jQuery may encounter issues when implemented with Angular's ng-repeat directive on objects

I have successfully implemented a jQuery hover function: $('.deleteButton').hover(function(){ $(this).css('opacity', '1'); }, function(){ $(this).css('opacity', '.5'); }); The function was functi ...

Persist AJAX request across page reloads

Seeking a solution to a perplexing dilemma that has left me incapable of finding a swift resolution. Perhaps there is someone here who can provide guidance. I am curious: if I initiate an AJAX request on my HTML page using jQuery and then trigger a refres ...

CSS - Using the left float property inline

.htabs { /* horizontal tabs */ display: table; } .htabs li { /* horizontal tab */ position: relative; float: left; background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGCAYAAADgzO9IAAAAMklEQVQIW2M8e3r/fw4OdgZk8OPHTwbGq5eP/Q ...

Trouble with the function to dynamically add and delete table rows

Currently utilizing Wordpress with WPMVC for my projects. In the process of dynamically adding table rows to a form in order to insert a new record into the table. Snippet of the code: views/admin/edit.php <h2>Edit Geozone</h2> <?php ec ...

Ensure that hyperlinks remain unbroken and do not split over two lines

When I generate links using $_GET [Array] to display in a box, I aim to have 5-10 links per line without any of them appearing on two lines. While I currently use {text-align:justify;} for consistent border spacing, I am seeking a method to prevent the lin ...

Can both Bootstrap 5 scroll-spy methods be utilized simultaneously on a single webpage?

I have a requirement for my website to have 2 navigation bars and also 2 sets of navigation links. I would like to implement scroll-spy functionality on both navigation bars, even though only one will be visible at a time. The issue I am facing is that w ...

Is there a way to set it up so that clicking on a small image will automatically switch to the corresponding larger size image?

For instance, I have 4 small images and 1 main image. When I click on a small image, the main image changes to display that selected picture. I was wondering if there is a specific value to place inside target=""? I prefer to only use HTML/CSS as I am no ...

How to Make Words Stand Out in a Textbox using Angular NgStyle and input::first-line Trick?

Is there a way to highlight the text in a textbox using Angular and Material design? I've tried the code below but it's not working for me. I'm looking to apply the highlighting conditionally based on a boolean variable called 'highlig ...

Attempting a second filter of the table using the dropdown results in no data being returned

I've developed a CRUD app using Angular 7, and I'm facing an issue. When I select a dropdown item for the first time, it shows the desired table data. However, on selecting another item for the second time, it returns nothing. Below is my compone ...

What could be causing the HTTP Error to pop up when I'm using mechanize?

I have been working on a code that aims to automate the process of opening a webpage and interacting with it. The implementation involves using the mechanize module within pydev. Here's the snippet of the code that I have developed so far: from bs4 i ...

The functionality of datepicker is not available in Bootstrap 4.1

Currently, I am developing a website at this domain. In this project, I aim to display a calendar when the user clicks on a search input box. This is the HTML code snippet I have implemented for the input boxes: <div class="dates"> <div class ...

The functionality of nth-child(odd) seems to be malfunctioning when there is a change

When I group certain elements together in one container, I like to make odd elements stand out by giving them a different background color. However, when I try to filter elements based on conditions and move unwanted elements to another class, the nth-chil ...

Guide on showcasing html and css in a preview using a Data URL

Currently, I have implemented two tab interfaces: one for entering HTML text and another for inputting CSS content. Following this, I have included a Preview section to visualize the combined output of both HTML and CSS elements. However, I am encountering ...