Is there a way to horizontally align the content in my footer section?

I am currently exploring React Material UI for the first time.

The table I am working with can be found here under the "Custom pagination actions" section.

Within this section, there is footer content containing buttons for rows per page, next, previous, etc...

I am having trouble centering this content in the middle. Currently, it is aligned to the right by default.

I attempted to add:

align="center"
justify="center"

but was unsuccessful.

This is how my footer code appears:

<TablePagination
    className=""
    align="center"
    justify="center"
    text-align="center"
    rowsPerPageOptions={[5, 10, {label: 'All', value: -1}]}
    // colSpan={12}
    count={props.rowsCount}
    rowsPerPage={props.rowsPerPage}
    page={props.page}
    SelectProps={{
        inputProps: {'aria-label': 'rows per page'},
        native: true,
    }}
    onChangePage={props.onChangePage}
    onChangeRowsPerPage={props.onChangeRowsPerPage}
    ActionsComponent={TablePaginationActions}
/>

Table pagination actions

import KeyboardArrowLeft from '@material-ui/icons/KeyboardArrowLeft';
import KeyboardArrowRight from '@material-ui/icons/KeyboardArrowRight';
import FirstPageIcon from '@material-ui/icons/FirstPage';
import LastPageIcon from '@material-ui/icons/LastPage';
import {makeStyles, useTheme} from '@material-ui/core/styles';
import {IconButton} from '@material-ui/core';

const useStyles = makeStyles((theme) => ({
    root: {
        flexShrink: 0,
        marginLeft: theme.spacing(2.5),
    },
}));

function TablePaginationActions(props) {
    const classes = useStyles();
    const theme = useTheme();
    const {count, page, rowsPerPage, onChangePage} = props;

    const c = console;
    const handleFirstPageButtonClick = (event) => {
        onChangePage(event, 0);
    };

    const handleBackButtonClick = (event) => {
        onChangePage(event, page - 1);
    };

    const handleNextButtonClick = (event) => {
        onChangePage(event, page + 1);
    };

    const handleLastPageButtonClick = (event) => {
        onChangePage(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
    };

    return (
        <div className={classes.root}>
            <IconButton
                onClick={handleFirstPageButtonClick}
                disabled={page === 0}
                aria-label="first page"
            >
                {theme.direction === 'rtl' ? <LastPageIcon /> : <FirstPageIcon />}
            </IconButton>
            <IconButton
                onClick={handleBackButtonClick}
                disabled={page === 0}
                aria-label="previous page"
            >
                {theme.direction === 'rtl' ? <KeyboardArrowRight /> : <KeyboardArrowLeft />}
            </IconButton>
            <IconButton
                onClick={handleNextButtonClick}
                disabled={page >= Math.ceil(count / rowsPerPage) - 1}
                aria-label="next page"
            >
                {theme.direction === 'rtl' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
            </IconButton>
            <IconButton
                onClick={handleLastPageButtonClick}
                disabled={page >= Math.ceil(count / rowsPerPage) - 1}
                aria-label="last page"
            >
                {theme.direction === 'rtl' ? <FirstPageIcon /> : <LastPageIcon />}
            </IconButton>
        </div>
    );
}

export default TablePaginationActions;

Answer №1

I came across a solution to my issue. The problem stemmed from React using the default class - MuiTablePagination-spacer, which had the following CSS:

MuiTablePagination-spacer {
    flex: 1 1 100%;
}

This caused the adjacent sibling div to shift to the right.

To resolve this, I centered my content by applying the following CSS:

.MuiToolbar-root {
    justify-content: center !important;
    border:2px solid red;
}

.MuiTablePagination-spacer {
    flex: 0 !important;
}

The class MuiToolbar-root already has display:flex, so I only added the style for justify-content. It was essential to remove the spaces on MuiTablePagination-spacer in order for everything to function correctly.

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

Managing a project with multiple pages using create-react-app

Lately, I've been experimenting with create-react-app and noticed that it only supports one default page called 'index.html'. If my project has multiple pages, can I still use create-react-app for front-end development? How can I achieve thi ...

Having trouble getting the group hover animation to function properly in Tailwind CSS

Just starting out with tailwind css and running into a little issue. The hover animation I'm trying to apply isn't working as expected in this case. Instead of seeing the desired animated background when hovering over the group, it seems the back ...

What are the reasons for avoiding placing CSS code directly within HTML?

Situation: My website is dynamically served, with all CSS and javascript directly embedded into the HTML document to optimize speed. Advantages: Reduces web requests Fewer files downloaded Speeds up webpage loading time Disadvantages: Potential cachin ...

td:before combined with vertical-align:middle

To achieve a table with square cells, I implemented the following CSS: table { width: 100%; table-layout: fixed; } td { text-align: center; vertical-align: middle; } td:before { content: ''; padding-top: 100%; float: ...

Generating an authentication token to access the GitHub API using Node.js

const axios = require('axios'); require('dotenv').config(); const getUsersFromApi = async (req, res) => { let { since } = req.query const { data, headers } = await axios.get(`https://api.github.com/users?since=${since}`, ...

Error: The term "FlatListItemSeparator" has not been declared in React Native

Just starting out with React Native, I decided to follow an online tutorial and create my own App.js file: import React, { useState, useEffect } from 'react'; import {View,Text,ImageBackground,FlatList, Image, TouchableHighlight } from 'reac ...

Adjust the hyperlink color of <a> to change when hovering over <tr>

When I hover over a <tr> tag, I want the color of the associated <a> element to change to white. I attempted to achieve this using jQuery in the following way: <script> $('tr').hover(function(){ $('a').cs ...

How can you create a unique JWT token when verifying a socket.io connection using Node and React?

As I delve into Socket.io, I've come across various security concerns that have been raised in this particular stack exchange post. In my specific scenario, I am utilizing socket.io in Node along with socket.io-client for React to establish robust co ...

I'm looking for a solution to reorganize my current state in order to display the image URL

My React component, which also utilizes TypeScript, is responsible for returning a photo to its parent component: import React, { useEffect, useState } from "react"; import axios from "axios"; export const Photo = () => { const [i ...

Disabled radio buttons are appearing as if they have been chosen

While working on customizing the styles of radio buttons in a form, I encountered an issue where disabled radio buttons appeared selected even though they were supposed to show as disabled. Here is the code snippet that I used: input ::-ms-clear { ...

Issue encountered with using the `useCallback` inside `useFocusEffect` in React Navigation V6 leading

While exploring the React Navigation V6 documentation, I came across examples of utilizing useCallback within useFocusEffect. However, when attempting to implement the same code, I encountered an "invalid-hook-call" error. For reference: https://reactnavi ...

What is the best way to customize the woocommerce.css file in the parent theme?

Currently, I have incorporated an ecommerce-friendly wordpress theme for my website in conjunction with woocommerce. To customize the design, I created a child theme and transferred the woocommerce.css file from the plugin into the css of the child theme, ...

Unable to locate 'react' for mdl module

Currently working on my first website using react, following a tutorial available at this link I am attempting to install and utilize the material lite module, but encounter a compilation error when starting npm with the following message: Error: Module ...

Use vertical gaps to separate items by applying the following technique:

One of my components is designed to act as a badge. The CSS for this component includes: https://i.sstatic.net/F0QZ6.png HTML: <div class="label label-as-badge"> {{ value.Termo }} <i class="fa fa-times"></i ...

Leverage the useRef hook with React Draggable functionality

Having recently delved into coding, I find myself navigating the world of Typescript and React for the first time. My current challenge involves creating a draggable modal in React that adjusts its boundaries upon window resize to ensure it always stays wi ...

Showcasing Information Using AngularJS from a Json Array

My goal is to present data from a JSON array in a table using the code below. However, all the data is currently being shown in one row instead of each record appearing on separate rows with alternating colors - grey for even rows and white for odd rows. I ...

Navigation is failing to float in the correct position

Having issues with my navigation positioning, specifically when it reaches the breakpoint. There's a strange gap on the right side that I can't seem to fix by adjusting padding or margin settings. I'm relatively new to this so please bear wi ...

What is the best way to upload a file to Firebase Storage using React?

I am facing difficulty uploading a file to Firebase in order to retrieve its getDownloadURL. This is the code snippet I currently have: import React, {useState, useEffect} from 'react' import { Container, Button, Row, Col, Form, Alert } from &ap ...

Object.assign changes the original array object in place

I am facing a challenge while attempting to modify the value of a specific index in my state, specifically the property post_comments. The issue lies in the fact that even though I am only modifying a copy of the state, the actual state is also being alter ...

Using JSON as HTML data within Flexbox for interactive hyperlink rollovers

Utilizing JSON to extract HTML data with unique html tags within Flex has presented a challenge. The limited support for HTML in Flex has made it difficult to implement a basic font color rollover effect on links. While Flex only allows for a few HTML tags ...