question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to change the color of CardHeader Title

See original GitHub issue

I cannot seem to be able to change the color of the CardHeader title text.

I have a ‘styles’ constant as follows:

const styles = theme => ({
  loginCard: {
    height: 200,
    width: 300
  },
  loginCardHeader: {
    backgroundColor: theme.palette.primary.main,
    color: '#fff'
  }
});

And my React.Component as follows:

class Login extends React.Component {
  render() {
    const { classes, theme } = this.props;

    return (
      <div>
        <Card className={classes.loginCard}>
          <CardHeader className={classes.loginCardHeader} title='Login' />
        </Card>
      </div>
    );
  }
}

The backgroundColor is applying to the CardHeader via loginCardHeader but the color is not.

Tech Version
Material-UI 1.0.0-beta.38
React 16.2.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

31reactions
oliviertassinaricommented, Mar 23, 2018
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import CardHeader from 'material-ui/Card';

const styles = theme => ({
  title: {
    color: 'red',
  }
});

class RecipeReviewCard extends React.Component {
  render() {
    const { classes } = this.props;

    return (
      <CardHeader
        classes={{
          title: classes.title,
        }}
        title="Shrimp and Chorizo Paella"
        subheader="September 14, 2016"
      />
    );
  }
}

RecipeReviewCard.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(RecipeReviewCard);

capture d ecran 2018-03-23 a 20 33 06

3reactions
jeffshekcommented, Aug 15, 2020
import { withStyles } from 'material-ui/styles';

is it possible without HOC?

Yep, works fine in hooks too.

const useStyles = makeStyles(() => ({
  title: {
    color: 'red',
    margin: 50,
    padding: 60,
    fontSize: 300,
  }
}));
const classes = useStyles();

<CardHeader className={classes.title} title="Delete My Account - WARNING PERMANENT" />
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you change the colour of the subheader in a material ...
The style I have applied seems to successfully change the CardHeader title but not the subheader? How can I get the subheader to...
Read more >
CardHeader API - Material UI - MUI
API reference docs for the React CardHeader component. ... The name MuiCardHeader can be used when providing default props or style overrides in...
Read more >
Card header background title - Material Design for Bootstrap
So for example in the code below I want to change the background colour where it says "Featured" to grey and the rest...
Read more >
Material-UI Card Custom Background Color, Header, Content ...
In this demo we'll create a mobile responsive card and configure the card header, content, and footer background color.
Read more >
Material UI CardHeader with All Props Enabled - YouTube
Do you want to build a full MUI app from beginning to end, learn every aspect of the sx prop, styled API, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found