Designing Material UI Button Styles

Hello, I recently started using Material UI and I'm facing some challenges in styling the components. Right now, I'm working on a sign-in page and trying to position the Submit button all the way to the bottom right corner. Any help or advice would be highly appreciated because it seems like the button is inheriting styles from unexpected sources. I've attempted adding

textAlign: 'right'

to buttonStyle but that didn't yield the desired result. I also tried adding

text-align: right;

to my .form-button CSS. The only noticeable change occurred when I removed the .App from Login.js

<div className='form-container'>
  ...
  <Button
    style={buttonStyle}
    className='form-button'
    variant='contained'>
    Log-In
  </Button>
</div>
...
const buttonStyle = {
  backgroundColor: '#527354'
};

In App.css

.App {
  text-align: center;
}

.form-button {
  width: 83px;
  height: 36px;

  box-shadow: 0px 1px 3px #00000033;
}

.MuiButton-label {
  color: var(--primary-white);
  font-family: 'Open Sans', sans-serif;
}

.form-container {
  max-width: 400px;
  margin: 2rem auto;
  overflow: hidden;
  padding: 0 2rem;
}

My main aim is to avoid inline styling as much as possible and keep everything within my style sheet. However, if it's too complicated or not achievable, I'll resort to inline styling (similar to how I did with the background-color).

Answer №1

As previously mentioned by keikai in the comments, you can refer to the Documentation available at material-ui.com/styles/basics for information on how to override styles.

If you're experiencing issues with styles being inherited from multiple sources,

I recommend using styled-components instead of importing global CSS, which can cause conflicts. Here's how you can do it:

First, install styled-components by running

npm install --save styled-components

This will create a CSS class that only applies to the specific component.

import styled from 'styled-components'

const MyDiv = styled.div`// this can be span, section, etc.

// add your style here for the div
your div style (optional)

// CSS class specific to the div
.form-container {
    max-width: 400px;
    margin: 2rem auto;
    overflow: hidden;
    padding: 0 2rem;
}

// add more classes if needed

`

Next, wrap your component with the newly created styled div like so:

// your newly created styled div  
<MyDiv>

   // component that requires styling
   <MyComponent />

</MyDiv>

The styles will now only be applied to MyDiv and MyComponent, ensuring no interference with other elements. It may take some time to adjust, but the benefits are worth it.

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 there a way to modify the dimensions of this container? (CSS)

After performing a search and clicking on a result, a white bubble pops up on the map. I am looking to use CSS to make this bubble smaller as it is currently too large. Can anyone provide guidance on how to achieve this? ...

What could be causing useEffect to trigger only after the component has been mounted in NextJS?

I'm currently encountering an issue with my implementation of a useEffect function that is supposed to act like a componentWillMount, but the behavior is not as expected. Within the code for Component (as demonstrated in the Codesandbox provided belo ...

Having trouble with screenProps in React Navigation's Stack.Navigator?

In my current project, I am working on setting up a stack navigator that includes two components: Login and List. Within the file containing the navigator (App.js), I have implemented a useState hook to manage state. However, I am encountering difficulties ...

Upon initiating a React Native project, five critical vulnerabilities become apparent

Upon starting my React Native project, I encountered 5 high severity vulnerabilities. Despite attempting to fix them with the command "npm audit fix --force", the issue persisted. I even went as far as reinstalling node.js and React Native, but the vulne ...

Preserve StepContent information within Material-ui Stepper during updates to the active step

I have a Stepper component with multiple steps, each containing several TextFields. The issue is that material-ui unmounts the step contents when you switch steps, causing all the data in the TextFields to be lost. My question is: Is there a way to prese ...

What are the best strategies for ensuring this website is fully optimized for all devices

Hi there, I've been struggling to make the header on my website responsive, but it doesn't appear to be functioning properly. Any assistance would be greatly appreciated. <!DOCTYPE html> <html lang="en"> <head> <meta name="v ...

Attempting to adjust table size in MPDF to fill the available height

I'm currently utilizing MPDF in order to create a PDF document from an HTML page that includes a table. My goal is to have the table expand to fill up the remaining space on the page. Here is the specific table I am working with: I want the final el ...

After transitioning from admin-on-rest to React-admin, React-admin fails to run properly

Upon switching from admin-on-rest to react-admin and initiating npm start, the create-react-app appears to run without any errors. However, an error is being logged in the console: Uncaught TypeError: Cannot read property 'prepareStyles' of un ...

`Unable to update the checked prop in MUI switch component`

The value of RankPermission in the switchPermission function toggles from false to true, but for some reason, the MUI Switch component does not update in the browser. I haven't attempted any solutions yet and am unsure why it's not updating. I&ap ...

Issues with table nesting functionality

I'm attempting to organize tables in a nested manner, instead of placing a table within each cell. My engineers have advised against simply styling the table to appear nested, and suggested that it would be more effective to wrap each header around th ...

Encountered an issue while trying to reset the dropdown menu values on a Dash application when utilizing a clear button

I'm attempting to add a clear button for users to reset the values in a dropdown menu. However, when I run the application, I encounter the following error preventing me from selecting an option in the dropdown: Unable to access property 'leng ...

The optimal method for selecting a button from a group of buttons on a calculator using pure JavaScript

I have developed an HTML/CSS code inspired by the Mac/Apple calculator design. It features buttons organized in 5 rows using flexbox. You can view my code on this codepen: <div class="wrapper"> <div class="calheader"> ...

Adding a CSV file to Mui-Datatables for data upload

Can someone guide me on the process of uploading a CSV file in Mui-Datatables and showcasing it in a table? I'm still learning about Mui-Datatable. ...

React Router and Error Boundary working together

I've configured my routes to wrap all components with an Error Boundary function renderComponentWithErrorBoundary(Component) { return () => { return ( <ErrorBoundary> <Component /> </ErrorBoundary> ) ...

What is the best way to retrieve the value of an input field in React when incorporating Material UI components?

I am working with a few radio input components that have been imported from material Ui react. Each radio input is wrapped in a FormControlLabel component. <FormControlLabel onClick={checkAnswerHandler} value={answer} control={<Radio color=&quo ...

What is the best way to implement ES2023 functionalities in TypeScript?

I'm facing an issue while trying to utilize the ES2023 toReversed() method in TypeScript within my Next.js project. When building, I encounter the following error: Type error: Property 'toReversed' does not exist on type 'Job[]'. ...

Creating email templates in React JS with Rails as the backend can be achieved by combining the front-end

Looking for suggestions on how to build email templates in React JS with Rails as the backend. Any thoughts? ...

Adjust the class based on the number of li elements

When there are more than two (li) tags, the ul tag should have the class "col_3"; otherwise it should have the class "col_2" For instance: If there are two columns <div class="container"> <ul class="col_2"> <li>One</li> ...

Exploring the Differences in Table Resizing between IE8, IE7, and Chrome when using table-layout:fixed

For my HTML timeline view, I encountered an issue that I'm hoping to resolve: I have a table row with 12 cells representing the 12 months, each with a colspan based on the number of days in that month. Another row in the same table contains the indiv ...

Unable to make jQuery animate top function work

I have three rectangles set up like this. I've managed to make them disappear when clicking the close button on the right side of each rectangle, but I'm struggling with getting the remaining rectangles to move upward to fill the empty space. Her ...