html - 如何在 flex wrap 中尽可能多地占用空间
问题描述
我创建了如下所示的自定义输入:
<div className="custom-input-container">
<label className="custom-input-label" htmlFor="input">Name</label>
<input type="email" className="custom-input" id="input" placeholder="Insert your name</input>
</div>
.custom-input-container {
min-width: 300px;
.custom-input {
width: 100%;
height: 56px;
}
}
我正在尝试创建一个有 2 行的布局。第一行有两个输入,应该占用整个可用空间,第二行输入应该占用可用空间的一半。
我试图实现这一点,但没有成功使用 flex 和 flex-wrap(仍然只占用 300px,flex-basis 也没有帮助)。
<div className="billing-details-container flex flex-wrap">
<CustomInput />
<CustomInput />
<CustomInput />
</div>
.billing-details-container {
& > *:first-child {
margin-bottom: 24px;
margin-right: 16px;
}
& > *:last-child {
margin-bottom: 50px;
}
}
知道如何实现吗?
解决方案
你的代码有很多问题。
您正在尝试通过添加 ClassName="" 为 html 提供类 正确的语法实际上是 class=""
您尚未关闭第二个输入。
<input type="email" className="custom-input" id="input" placeholder="插入你的名字
应该
<input type="email" class="custom-input" id="input" placeholder=">插入你的名字
您也不需要标签。你为什么给输入一个特定的ID?
- 您不能将标签 for="" 用于带有 id 的输入。您应该给它一个名称以在标签中使用它。
这是我写的代码。我希望这就是你的意思,我删除了你的标签,因为无论如何你都在使用占位符。如果需要,您可以自己添加回来。
// ******************** 开始 HTML ******************** //
<div class="custom-input-container">
<div class='input-group'>
<input type="email" name="input" placeholder="Insert your name">
<input type="email" name="input" placeholder="Insert your name">
</div>
<input type="email" name="input" placeholder="Insert your name">
</div>
// ******************** END HTML ******************** // // ** ****************** 开始 CSS ******************** //
.custom-input-container {
display: flex;
flex-direction: column;
min-width: 300px;
background: orange;
}
.custom-input-container .input-group {
display: flex;
flex-direction: row;
}
.custom-input-container .input-group input {
width: 50%;
height: 56px;
}
.custom-input-container input {
height: 56px;
}
// ******************** 结束 CSS ******************** //
推荐阅读
- oracle - 集合元素类型的 %TYPE
- angular - 在叠加层中动态渲染组件
- java - 读写对象字段
- javascript - TypeScript:如何从对象初始化派生类?
- excel - VBA - 特定工作表和特定范围的条件格式
- javascript - 如何在 postgres 中重新启动连接?
- groovy - 如何在 Jenkins 的 Groovy 脚本中使用 sed 进行字符串替换
- python - 主题标签会干扰正则表达式中的前瞻吗?
- awk - 从 tail -f /var/logmessage 创建变量
- azure-cognitive-search - 了解评分结果 - 精确分数低于部分分数