admin管理员组文章数量:1303063
I am using createMuiTheme
to set customize my theme with Material UI. How do I set a specific font for the header, body, and button tags?
I'm assuming it would be customizing the typography ponent in the theme. And then selecting it from the App ponent. But can't find any documentation regarding this.
Theme file:
import { createMuiTheme } from "@material-ui/core/styles";
export default createMuiTheme({
typography: {
fontFamily: ["campton-book", "campton-light", "campton-medium"].join(",")
//something here setting specific font family for specific tags?
}
});
import React, { Component } from "react";
import PropTypes from "prop-types";
import { withStyles, MuiThemeProvider } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
import Theme from "../Theme";
const styles = theme => ({
root: {
flexGrow: 1
}
});
class Tools extends Component {
render() {
const { classes } = this.props;
return (
<MuiThemeProvider theme={Theme}>
<Typography variant="h2">Some text here as h2 and the "campton-light" font family</Typography>
<Typography variant="body1">Some text here as body1 and the "campton-book" font family</Typography>
<Typography variant="overline">Some text here as overline and the "campton-medium" font family</Typography>
</MuiThemeProvider>
);
}
}
Apps.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(Apps);
I am using createMuiTheme
to set customize my theme with Material UI. How do I set a specific font for the header, body, and button tags?
I'm assuming it would be customizing the typography ponent in the theme. And then selecting it from the App ponent. But can't find any documentation regarding this.
Theme file:
import { createMuiTheme } from "@material-ui/core/styles";
export default createMuiTheme({
typography: {
fontFamily: ["campton-book", "campton-light", "campton-medium"].join(",")
//something here setting specific font family for specific tags?
}
});
import React, { Component } from "react";
import PropTypes from "prop-types";
import { withStyles, MuiThemeProvider } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
import Theme from "../Theme";
const styles = theme => ({
root: {
flexGrow: 1
}
});
class Tools extends Component {
render() {
const { classes } = this.props;
return (
<MuiThemeProvider theme={Theme}>
<Typography variant="h2">Some text here as h2 and the "campton-light" font family</Typography>
<Typography variant="body1">Some text here as body1 and the "campton-book" font family</Typography>
<Typography variant="overline">Some text here as overline and the "campton-medium" font family</Typography>
</MuiThemeProvider>
);
}
}
Apps.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(Apps);
Share
Improve this question
asked Mar 26, 2019 at 22:29
TinaTina
853 silver badges9 bronze badges
1 Answer
Reset to default 7Below is the syntax for controlling the font-family for different text variants.
The easiest way to look at the properties available in the theme is to look at the structure of the default theme: https://material-ui./customization/default-theme/
const theme = createMuiTheme({
typography: {
h1: {
fontFamily: "Comic Sans MS"
},
h2: {
fontFamily: "Arial"
},
h3: {
fontFamily: "Times New Roman"
},
h4: {
fontFamily: "verdana"
},
button: {
fontFamily: "Comic Sans MS"
}
}
});
本文标签:
版权声明:本文标题:javascript - How do I set custom fonts for header, body, and button tags for Material UI? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741726728a2394655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论