Center the table element horizontally on an HTML page

I am facing an issue where my angular material and css table are not taking the full width of my div. Additionally, I want to set the image in the header as a background. Here is the link to my work on StackBlitz: https://stackblitz.com/github/lnquaidorsay/bibliofront or

<div class="container">
    <div fxFlex="60">
        <div class="mat-elevation-z8">
            <table mat-table [dataSource]="dataSource">

                <!-- Position Column -->
                <ng-container matColumnDef="position">
                    <th mat-header-cell *matHeaderCellDef> No. </th>
                    <td mat-cell *matCellDef="let element"> {{element.position}} </td>
                </ng-container>

                <!-- Name Column -->
                <ng-container matColumnDef="name">
                    <th mat-header-cell *matHeaderCellDef> Name </th>
                    <td mat-cell *matCellDef="let element"> {{element.name}} </td>
                </ng-container>

                <!-- Weight Column -->
                <ng-container matColumnDef="weight">
                    <th mat-header-cell *matHeaderCellDef> Weight </th>
                    <td mat-cell *matCellDef="let element"> {{element.weight}} </td>
                </ng-container>

                <!-- Symbol Column -->
                <ng-container matColumnDef="symbol">
                    <th mat-header-cell *matHeaderCellDef> Symbol </th>
                    <td mat-cell *matCellDef="let element"> {{element.symbol}} </td>
                </ng-container>

                <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
                <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
            </table>

            <mat-paginator [pageSizeOptions]="[5, 10, 20]"></mat-paginator>
        </div>

    </div>
</div>

Can anyone provide any suggestions or solutions for this issue?

Answer №1

The products table appears to be already set at 100% width. It looks like you've successfully resolved the issue.

Regarding the header background, please remove the image from the mat-toolbar-row element and insert this CSS code into the mat-toolbar:

mat-toolbar {
  background-image: url('<path/to/image>');
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
}

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

Disappearing sticky-top navbar in Bootstrap when scrolling

I'm having trouble with the navbar on my website. Currently, it sticks to the top until I scroll out of the hero-image and then disappears. I would prefer the navbar to remain present throughout the entire page. Any suggestions on how to achieve this? ...

Repairing the formatting of the content inside a dynamically growing div

Check out the code on this Fiddle link, <!DOCTYPE html> <body> <div class="test"> <h1>?</h1> <p>This paragraph gives more information that can be accessed by hovering over the question mark (Move your mouse awa ...

Get rid of any empty space in the image preview icon

Is there a way to eliminate the white space that appears when mixing landscape and portrait images? I want the images to move up and fill the space, even if they don't align perfectly. Additionally, I would like the images to resize based on the scal ...

Embedding the Angular Material date picker when the page loads using an HTML tag

Currently, I am in need of a solution where the material datepicker (the datepicker itself, not just the icon) is visible on the page by default. The goal is to always have the datepicker displayed without needing to click on an icon. If anyone could pro ...

Addressing some minor visual inconsistencies in an HTML bullet-pointed list

After reviewing my current code, it is displaying the following: https://i.stack.imgur.com/dvjrc.jpg I am attempting to make the following changes: Ensuring each line in the list fits properly within its corresponding box by utilizing vertical-align: to ...

Adding and adjusting the size of different DIV elements within a shared area

Looking to create a dynamic bar with the ability to add multiple child DIVs (similar to this: https://i.stack.imgur.com/tdWsq.jpg). Utilizing jQuery, jQuery UI, Bootstrap, and various plugins. The structure for the div (or span) system could be structured ...

Creating a foundational design with Bootstrap 5, featuring a sidebar that scrolls seamlessly and a stunning fixed

I'm having some trouble figuring out the layout for a webapp I want to develop. LAYOUT IMAGE What I envision is a sidebar menu on the "S" section that can be scrolled independently, and a large image on the "I" section that changes based on th ...

Struggling with getting the local slick slider to run smoothly

After installing the slick slider plugin and trying out some basic examples on jsfiddle, I encountered an issue when running it locally. For some reason, the results I get when testing it on my local environment are different from what I see on jsfiddle. ...

Aligning the row div in the center horizontally

Is there a way to center all columns in a row horizontally in Bootstrap 4? The first row is centered correctly, but the columns in the second row are not aligned properly even though they have the same class. Here's my code: <!doctype html> &l ...

Utilizing ReactJS to fetch data from Material-UI's <TableRow/> component upon selection - a comprehensive guide

I've integrated Material-UI's <Table/> (http://www.material-ui.com/#/components/table) component with <TableRow/> containing checkboxes in a ReactJS project. While I can successfully select rows by checking the boxes, I am struggling ...

Tips for displaying nested JSON arrays in HTML using Ember.js

I'm having trouble displaying the JSON data I get in app.js using HTML. Any suggestions? Here is the code for app.js (I am confident that $.post is returning valid JSON) App.CadeirasRoute = App.AuthenticatedRoute.extend({ model: function() { a ...

css hover function not operational with back to top button

I have implemented a back to top button using the following resource: Although the button is functioning as expected, I am encountering an issue with the hover effect. In Chrome inspector, manually forcing hover on .cd-top does not apply the CSS style as ...

Refreshing the page to dynamically alter background and text hues

I'm currently dealing with a website that generates a random background color for a div every time it is refreshed. I have a code that successfully accomplishes this: var colorList = ['#FFFFFF', '#000000', '#298ACC', &ap ...

Instructions for converting a blob URL into an audio file and securely storing it on the server

After successfully recording and adding the audio to my HTML page within the audio tag, I managed to obtain the blob source URL from the tag using the following line: var source = document.getElementById("Audio").src; The blob source URL looks ...

What is the proper way to utilize the name, ref, and defaultValue parameters in a select-option element in React Meteor?

I recently developed a Meteor project using ReactJS. I have a Create/Edit page where I use the same input field for various form elements. Here is an example of code snippet that I currently have: <FormGroup> <ControlLabel>Province</Control ...

What could be causing the issue with object-fit not functioning properly within a container with a max

My goal is to insert a video into a container that has a width of 100% and automatically adjusts its height while maintaining the aspect ratio, but with a maximum height set. I want the video to completely fill the container even if some parts are cropped ...

Unable to write to csv file in UTF-8 using PHP fwrite, experiencing issues

Looking for assistance with handling PHP fwrite as CSV file is displaying incorrect characters. The output appears like this: općšpšćšćšp ćpšćpšćp šćpšćpšć This is the PHP code being used fo ...

Positioning Bug in FF/IE with Absolute Placement

It appears that Chrome is the only browser displaying my code correctly. While testing in Firefox and Internet Explorer, I have noticed that my position:absolute is being affected by the border size, unlike in Chrome where it remains unaffected (which is ...

The issue arises when jQuery functions fail to function properly due to data being called after the

What I am about to bring up may present a challenge, but I will do my best to explain it clearly. I have designed my website with only one main webpage (index.php). The HTML and content for various pages are saved in a PHP script. So, when a user chooses ...

Troubleshooting: Angular 13 input radio not recognizing checked condition

Storing selectedKitchenId in localstorage, and checking if selectedKitchenId === kitchen.id to determine which radio button should be selected. Cannot figure out why the checked condition is not working as expected, even though when I use a strong tag to d ...