css - 关闭按钮位置错误
问题描述
我有一个对话框,其中有一个 X 作为关闭按钮。我的代码中有一些片段如下所示。出于某种原因,它正在向下推标题文本,并在其上方留出空间。但我希望它是水平的,没有浪费的空间。
我哪里错了?
const useStyles = makeStyles(theme => ({
root: {
flexGrow: 1,
},
paper: {
padding: theme.spacing(2),
textAlign: 'left',
color: theme.palette.text.secondary,
height: '100%',
},
dialog: {
position: 'absolute',
// left: 10,
top: 50,
},
closeButton: {
position: 'relative',
right: theme.spacing(1),
top: theme.spacing(1),
color: theme.palette.grey[500],
},
customizedButton: {
position: 'relative',
left: '60',
top: '60',
color: 'silver',
},
}));
<Dialog
id="myDialog"
classes={{ paper: classes.dialog }}
//Modal dialog for advice on position
onClose={handleCloseTagInstructions}
open={openTagInstructions}
// onClose={handleCloseImportPGN}
aria-labelledby="form-dialog-title"
fullWidth={true}
// maxWidth={'md'}
>
<DialogActions>
<IconButton
className={classes.customizedButton}
onClick={handleCloseTagInstructions}
>
<CloseIcon />
</IconButton>
</DialogActions>
<TagContent tagText={currentTag} tagColour={tagColour} />
</Dialog>
解决方案
我切换到绝对,一切都很好。
const useStyles = makeStyles(theme => ({
root: {
flexGrow: 1,
},
paper: {
padding: theme.spacing(2),
textAlign: 'left',
color: theme.palette.text.secondary,
height: '100%',
},
dialog: {
position: 'absolute',
// left: 10,
top: 50,
},
closeButton: {
position: 'absolute',
right: theme.spacing(1),
top: theme.spacing(1),
color: theme.palette.grey[500],
},
customizedButton: {
position: 'absolute',
left: '60',
top: '20px',
color: 'silver',
},
}));
请注意,我使用 20px 添加了像素。
推荐阅读
- c - 查找中位数而不对数组进行排序
- mysql - 我正在尝试使用 multer 显示我上传到后端的图像
- javascript - 随机图像生成器在目录中找不到图像
- android - 如何使用 Kotlin 打开 Android Studio 的断言
- r - excel文件按行合并的问题
- c++ - 如何使用运算符重载来简化两个分数的加法?
- aqueduct - 是否可以修改为具有 WHERE 子句的连接对象返回的属性?
- bash - bash:在进程替换中使用大括号通配符时重定向不明确
- java - 我不知道为什么 ArrayIndexOutOfBoundsException 发生在单独的链接中
- regex - 使用正则表达式将 htaccess 中的大写替换为小写