Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the color of CardHeader Title #10779

Closed
rjkowalewski opened this issue Mar 23, 2018 · 8 comments
Closed

How to change the color of CardHeader Title #10779

rjkowalewski opened this issue Mar 23, 2018 · 8 comments
Labels
support: Stack Overflow Please ask the community on Stack Overflow

Comments

@rjkowalewski
Copy link

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
@oliviertassinari oliviertassinari added the support: Stack Overflow Please ask the community on Stack Overflow label Mar 23, 2018
@support
Copy link

support bot commented Mar 23, 2018

👋 Thanks for using Material-UI!

We use the issue tracker exclusively for bug reports and feature requests, however,
this issue appears to be a support request or question. Please ask on StackOverflow where the
community will do their best to help. There is a "material-ui" tag that you can use to tag your
question.

If you would like to link from here to your question on SO, it will help others find it.
If your issues is confirmed as a bug, you are welcome to reopen the issue using the issue template.

@support support bot closed this as completed Mar 23, 2018
@oliviertassinari
Copy link
Member

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

@hiteshsahu
Copy link

Change size and color :

title: {
    color: "red",
    fontSize: 25
  },

@nemethricsi
Copy link

import { withStyles } from 'material-ui/styles';

is it possible without HOC?

@jeffshek
Copy link
Contributor

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" />

@sanath-git
Copy link

How to use the default theme? I get a error saying theme is not defined.

@sanath-git
Copy link

Why cant i use this => theme.palette.primary.light

@nemethricsi
Copy link

Why cant i use this => theme.palette.primary.light

Do you have the theme object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support: Stack Overflow Please ask the community on Stack Overflow
Projects
None yet
Development

No branches or pull requests

6 participants