reactjs - 在带有按钮的 App Bar 中 material-ui / core ': v3.9.1 裁剪背景图片
问题描述
在带有按钮的 App Bar 中 material-ui / core ': v3.9.1 裁剪背景图像。
在带有按钮 material-ui / core ': v3.0.3 的 App Bar 中一切正常
为什么?什么可以像在 v3.0.3 中一样工作。我的代码:
// https://material-ui.com/api/app-bar/(带按钮的应用栏)
import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import AppBar from "@material-ui/core/AppBar";
import Toolbar from "@material-ui/core/Toolbar";
import Typography from "@material-ui/core/Typography";
import Button from "@material-ui/core/Button";
import IconButton from "@material-ui/core/IconButton";
import { Link } from "react-router-dom";
import MenuIcon from "@material-ui/icons/Menu";
import logoRa from "../assets/images/all/SunRa48.png";
const styles = {
root: {
flexGrow: 1,
},
grow: {
flexGrow: 1,
},
menuButton: {
marginLeft: -12,
marginRight: 20,
},
logo: {
backgroundImage: `url(${logoRa})`,
backgroundSize: 45,
backgroundPosition: "2px 2px",
backgroundRepeat: "no-repeat",
borderRadius: "0%",
marginRight: 10,
},
};
function ButtonAppBar(props) {
const { classes } = props;
return (
<div className={classes.root}>
<AppBar position="static">
<Toolbar>
<IconButton className={classes.menuButton} color="inherit" aria-label="Menu">
<MenuIcon />
</IconButton>
<IconButton className={classes.logo} component={Link} to="/aboutme" title="AboutMe" aria-label="logo" />
<Typography variant="h6" color="inherit" className={classes.grow}>
News
</Typography>
<Button color="inherit">Login</Button>
</Toolbar>
</AppBar>
</div>
);
}
ButtonAppBar.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(ButtonAppBar);
解决方案
在 3.1.0 版本之前,IconButton
具有 48px 的显式宽度和高度。
在 3.1.0 版本中,这些已被删除以支持更灵活的IconButton
. 由于您将徽标作为背景图像,因此尺寸缩小了。
您可以通过将宽度和高度添加到徽标类中来恢复旧行为:
logo: {
backgroundImage: `url(${logoRa})`,
backgroundSize: 45,
backgroundPosition: "2px 2px",
backgroundRepeat: "no-repeat",
borderRadius: "0%",
marginRight: 10,
width: 48, // added
height: 48 // added
}
推荐阅读
- android - contentResolver 中的 loadThumbnail() 是否会从默认 Thumbnails 文件夹中加载缩略图?
- webpack - 如何仅为 .mod.css 文件启用 css 模块?下一页
- python - 将行向量数据框除以标量数据框
- css - 如何将伪 webkit 滚动条的 z 索引设置在所有元素之上
- hibernate - Grails 多对多连接表
- asp.net - VB.NET/ASP.NET 使用 OAuth 发送自动 Gmail 外发邮件
- mysql - 需要 mysqlclient 1.3.13 或更新版本;你有 0.9.3
- node.js - 等待每个 playStream() 完成,然后再开始读取下一个
- mysql - 为什么 MySQL 查询与我的不匹配?
- python - Tensorflow 模型未正确加载 - INFO:tensorflow:Saver 未创建,因为图中没有要恢复的变量