css - 如何将 Height 属性添加到自定义 React 组件
问题描述
嘿,我正在创建一个包含两个文本框的 React 表单。我创建了一个自定义文本框,但我希望它们具有不同的高度,我该如何实现?
表单.js
<Label>Job Description</Label>
<Textarea
type="textarea"
name="description"
focus={isFocused}
value={description}
onFocus={handleOnFocus}
onChange={handleTitleChange}
/>
<Label>Job Requirements</Label>
<Textarea
type="textarea"
name="requirement"
focus={isFocused}
value={requirement}
onFocus={handleOnFocus}
onChange={handleTitleChange}
/>
样式化组件
const Textarea = styled.textarea`
width: 100%;
border: 1px solid #d3d3d3;
outline: none;
resize: none;
transition: 0.1s ease-out;
height: 80px;
background-color:white;
`;
现在我已将高度指定为 80px,但我希望Job requirement
文本框为 40px
解决方案
可以通过 props 配置
<Textarea type="textarea" name="description" height="40px" />
<label>Job Requirements</label>
<Textarea type="textarea" name="requirement" height="80px" />
接着
const Textarea = styled.textarea`
width: 100%;
border: 1px solid #d3d3d3;
outline: none;
resize: none;
transition: 0.1s ease-out;
height: ${(props) => props.height};
background-color: white; `;
检查我的 沙箱
推荐阅读
- java - 查询注释不适用于和/或运算符
- c++ - 函数的堆栈区域确定
- html - ASP .NET 应用程序 - 将图像而不是文本添加到 asp-route-returnUrl
- sas - 使用 SAS 使用多个条件删除重复项
- c# - ASP.NET MVC 按日期筛选结果返回 0 个结果
- bash - `grep` 导致 bash 脚本停止
- azure - Azure 容器实例组的指标(按状态)
- python - 如何有效地存储用于 API 执行的类似 SQL 查询
- airflow - 气流树视图任务排序
- javascript - 如何使用for循环(JavaScript)对不同数组中相同索引处的元素求和