我想使用material-ui-next的CSS-in-JS,withStyles还是主题在Web应用程序的主体中设置背景图像?我希望尽可能避免使用外部CSS文件。
答案 0 :(得分:1)
您可以使用“ @ material-ui / core / styles”中的withStyles通过“ @global”将css注入外部范围
import React, { Fragment } from "react";
import CssBaseline from "@material-ui/core/CssBaseline";
import { withStyles } from "@material-ui/core/styles";
import Main from "./Main";
const styles = theme => ({
"@global": {
body: {
backgroundImage: "url('/media/landing.jpg')",
backgroundRepeat: "no-repeat",
backgroundPosition: "center center",
backgroundSize: "cover",
backgroundAttachment: "fixed",
height: "100%"
},
html: {
height: "100%"
},
"#componentWithId": {
height: "100%"
}
}
});
const App = () => {
return (
<Fragment>
<CssBaseline />
<Main />
</Fragment>
);
};
export default withStyles(styles)(App);