【发布时间】:2021-04-02 06:23:02
【问题描述】:
我正在为我的项目制作页脚。 我正在为页脚使用材质 UI 网格,所以我想在底部添加徽标,但我不明白为什么它有正确的填充(我猜它是填充,不确定)。
Code Footer.js React 组件 ->
import React from "react";
import CssBaseline from "@material-ui/core/CssBaseline";
import Typography from "@material-ui/core/Typography";
import { makeStyles } from "@material-ui/core/styles";
import Container from "@material-ui/core/Container";
import Link from "@material-ui/core/Link";
import Grid from "@material-ui/core/Grid";
import Box from "@material-ui/core/Box";
import logoWhite from "../logos/logoWhite.png";
function Copyright() {
return (
<Typography variant="body2" color="textSecondary">
{"Copyright © "}
<Link color="inherit" href="https://material-ui.com/">
Your Website
</Link>{" "}
{new Date().getFullYear()}
{"."}
</Typography>
);
}
const useStyles = makeStyles((theme) => ({
root: {
display: "flex",
flexDirection: "column",
minHeight: "100vh",
},
main: {
marginTop: theme.spacing(8),
marginBottom: theme.spacing(2),
},
footer: {
padding: theme.spacing(3, 2),
marginTop: "auto",
backgroundColor: "#312D2D",
color: "white",
height: 167,
},
footerGrid: {
width: "20%",
marginLeft: 40,
marginTop: 35,
pading:0,
border: "2px solid red"
},
footerLogo: {
minWidth: "50%",
maxWidth: "60%",
width: "auto",
margin: "0 auto",
backgroundColor: "pink"
},
footerGridLogo: {
width: "fit-content",
pading:0,
borderRight: "1px solid white",
margin:0,
border: "4px solid green"
}
}));
export default function Footer() {
const classes = useStyles();
return (
<div className={classes.root}>
<CssBaseline />
<footer className={classes.footer}>
<Grid spacing={0} className={classes.footerGrid}>
<Grid item className={classes.footerGridLogo}>
<img
src={logoWhite}
alt="brandlogo"
className=""
className={classes.footerLogo}
/>
</Grid>
</Grid>
</footer>
</div>
);
}
【问题讨论】:
-
@NearHuscarl 它似乎还没有工作。
-
在您的
footerGridLogo样式中,通过将显示设置为 flex 并将 justify-content 设置为居中来尝试居中对齐图像。 -
好吧,有点工作,但网格没有环绕徽标;-(
-
我把
footerGrid样式中的width改成fit-content,this是你想要的吗? -
是的,谢谢!
标签: reactjs material-ui react-grid-layout