css - Material-UI style buttons on the right
问题描述
How do you align buttons on the right using Material-UI's makeStyles function?
I have tried using CSS's margin-right: 0
tag, but there is an error using '-' with makeStyles.
I renamed it as 'marginRight' and it still does not work. Also mr: 0
is not valid either. (Using Material-UI's spacing).
The code is trying to make the UI similar to stackOverflow's title layout.
import React from 'react';
import { makeStyles } from "@material-ui/core/styles";
import { Box, Button } from "@material-ui/core";
const style = makeStyles({
titleItemRight: {
color: 'white',
backgroundColor: 'blue',
top: '50%',
height: 30,
align: 'right',
position: 'relative',
transform: 'translateY(-50%)',
}
});
const App = () => {
const classes = style();
return (
<div>
<Box className={classes.titleBar}>
<Button variant='text' className={classes.titleItemRight}>Sign In</Button>
</Box>
</div>
);
};
解决方案
改变,
align: 'right'
至,
float: 'right'
所以代码看起来像,
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import { Box, Button } from "@material-ui/core";
const style = makeStyles({
titleItemRight: {
color: "white",
backgroundColor: "blue",
top: "50%",
height: 30,
float: "right",
position: "relative",
transform: "translateY(-50%)"
}
});
const App = () => {
const classes = style();
return (
<div>
<Box className={classes.titleBar}>
<Button variant="text" className={classes.titleItemRight}>
Sign In
</Button>
</Box>
</div>
);
};
推荐阅读
- python - "是什么意思
's'>" 是什么意思? - javascript - 如何使用 R 抓取由 js/ajax 技术生成的网站数据?
- macos - 使用 Electron-Builder 构建后运行 .dmg 应用程序会导致“应用程序意外退出”。
- powerbi - PowerBI:当满足任一 VAR 时返回计算
- php - 在 Wordpress 中调用动态数据
- javascript - 这段代码如何找到两个对象数组之间的差异?
- r - 从当地时间到国际时间?
- docker-compose - Docker 数据库迁移/部署到 DigitalOcean
- vb.net - 如何检测 webbrowser-control 中的错误
- html - 如何使用 CSS 将单行文本向上移动 10 像素或 15 像素?