css - ReactJS 中的问题居中组件
问题描述
我来自 React Native,所以我仍在适应 ReactJS。我有两个按钮,一个普通按钮和一个图标按钮。我想将常规按钮居中并在屏幕底部放置图标按钮。我试过使用 justifyContents: 'center' 和我的代码中显示的类似设置,但它似乎不起作用。我所有的代码都在下面,注释显示了我的按钮代码在哪里。感谢您提供任何帮助。
import React, {useState} from 'react';
import SettingsIcon from '@material-ui/icons/Settings';
import { Button , TextField, IconButton} from '@material-ui/core';
function App() {
const [task, setTask] = useState("");
const [goals, setGoal] = useState(["test"]);
const addGoal = () => {
setGoal([...goals, task]);
};
const listItems = goals.map((number) =>
<li>{goals}</li>
);
return (
<div style={{padding: 50, flexDirection: 'column'}}>
<div style = {{display: 'flex', fontFamily: 'Roboto', fontSize: 55}}>
<text>Tuesday</text>
</div>
<text style = {{display: 'flex', fontFamily: 'Roboto', fontSize: 45, marginBottom: 50}}>11:45</text>
<div style = {{marginBottom: 20}}>
<TextField inputProps={{style: {fontFamily: 'Roboto'}}} InputLabelProps = {{style: {fontFamily: 'Roboto'}}} id="standard-basic" autoComplete='off' label="New Goal" fullWidth value = {task} onChange = {e => setTask(e.target.task)}/>
</div>
//TRYING TO CENTER THIS BUTTON
<div style = {{display: 'flex', alignSelf: 'center', justifContent: 'center'}}>
<Button variant="outlined" disableElevation size = "medium">
Add Goal
</Button>
</div>
<div style = {{flexDirection: 'column', paddingTop: 40}}>
<ui>listItems</ui>
</div>
//TRYING TO HAVE THIS AT THE BOTTOM OF THE PAGE
<div style = {{display: 'flex', justifContent: 'flex-end'}}>
<IconButton>
<SettingsIcon/>
</IconButton>
</div>
</div>
);
};
export default App;
解决方案
要回答你的问题,我想你错过了,但它应该是 justifyContent,而不是 justifContent。
<div style = {{display: 'flex', alignSelf: 'center', justifyContent: 'center'}}>
<div style = {{display: 'flex', justifyContent: 'flex-end'}}>
推荐阅读
- python - Python:复制的对象仍然与原始对象更改
- networking - 如果分段的 IP 数据报被丢弃(即多分之一)会发生什么?
- sql - 你能增加 SQL Server 的查询优化器找到最佳查询计划的时间吗?
- python - 贝叶斯神经网络
- json - 在调用另一个功能文件时传递 JSON 数组
- python - 如何在单个列表索引中对循环元素进行分组
- yaml - gitlab-ci 小写变量
- hbase - brew service install hbase和从官网下载src/bin文件有什么区别?
- javascript - 使函数等待直到第一个函数完成运行
- python - 在使用python的图像中围绕整个文本块绘制边界框