css - 占用填充元素的剩余空间的问题
问题描述
我正在尝试创建一个包含文本和按钮的元素,该按钮将元素作为 todo 项目的一部分删除。
我遇到了一个问题,我无法将文本居中,也无法填充元素内剩余的高度和右侧的剩余空间,如图所示。
我正在使用 ReactJS 和 styled-components 库。
这是样式组件(我认为相关的块是:StyledAddButton 和 StyledP)
import styled from "styled-components";
export const StyledList = styled.div`
font-family: "Open Sans";
justify-content: center;
text-align: center;
align-items: center;
max-width: 40%;
margin: 8rem auto;
box-shadow: red;
min-height: 60vh;
-webkit-box-shadow: 0px 0px 20px 5px rgba(176, 203, 235, 1);
-moz-box-shadow: 0px 0px 20px 5px rgba(176, 203, 235, 1);
box-shadow: 0px 0px 20px 5px rgba(176, 203, 235, 1);
border-radius: 107px 107px 107px 107px;
-moz-border-radius: 107px 107px 107px 107px;
-webkit-border-radius: 107px 107px 107px 107px;
border: 7px solid #abbcd9;
text-align: center;
height: 100%;
`;
export const StyledButtonList = styled.div`
display: flex;
justify-content: center;
`;
export const StyledXButton = styled.button`
color: #fff;
padding: 10px 30px;
border: 1px solid rgba(255, 255, 255, 0.5);
background: #ef3f5a;
width: 100%;
height: 100%;
`;
export const StyledButtonInput = styled.input`
border: 0;
border-bottom: 1px solid gray;
text-align: center;
padding: 7px 0;
`;
export const StyledTodoWindow = styled.div`
margin: 8rem auto;
`;
export const StyledTodo = styled.div`
display: flex;
flex-direction: column;
width: 50%;
margin: auto;
height: 100%;
`;
export const StyledAddButton = styled.button`
background-color: #abbcd9;
border: none;
font-family: "Open Sans";
color: white;
font-size: 16px;
background-color: white;
color: black;
`;
export const StyledP = styled.p`
display: flex;
align-items: center;
justify-content: space-between;
box-shadow: 4px 8px 16px rgba(0, 0, 0, 0.3);
padding: 10px;
height: 100%;
`;
export const StyledH1 = styled.h1`
font-family: "Open Sans";
`;
这是 app.js 的返回部分:
return (
<StyledList>
<GlobalFonts />
<StyledTodoWindow>
<h1>What are the plans for today?</h1>
<form>
<StyledButtonInput
type="text"
placeholder="Add Todo"
value={input}
onChange={(e) => setInput(e.target.value)}
></StyledButtonInput>
<StyledAddButton
onClick={(e) => {
e.preventDefault();
setTodos([
...todos,
{
name: input,
id: uuidv4(),
},
]);
}}
>
Add
</StyledAddButton>
{todos.length > 0 ? (
<StyledH1>Your todos:</StyledH1>
) : (
<h2>Nothing?! :)</h2>
)}
</form>
<StyledTodo>
{todos.map((todo) => {
return (
<StyledP>
{todo.name}{" "}
<StyledButtonList>
<StyledXButton onClick={() => deleteTask(todo.id)}>
x
</StyledXButton>{" "}
</StyledButtonList>
</StyledP>
);
})}
</StyledTodo>
{todos.length > 0 ? (
<button onClick={() => clearAll()}> Remove all </button>
) : (
""
)}
</StyledTodoWindow>
</StyledList>
);
};
解决方案
推荐阅读
- python - 同一com端口上python中串行对象的多个实例
- linux - 让进程在后台挂起/运行并写入同一个文件
- google-sheets - 谷歌表格 - 根据字符串输入在公式中包含表格名称
- c++ - 使用向量时的无符号整数或迭代器?
- postgresql - JOOQ 时间戳字段默认值与数据库默认值不同
- android - 在 androids Talkback 可访问性中将缩写或首字母发音为单个字符
- java - 我将如何写入缓冲区并在 Java 画布中绘制它?
- python - 我如何按三列分组并计数并将结果传输到一个数据框中
- qt - 在特定时间执行函数 QT
- jquery - 仅在 IE11 上出现 Jquery 错误 - Foreach(anchor) 语法错误