html - 输入框形状受父 div 限制
问题描述
我想实现类似于这张照片的登录区域的外观。
我目前的 HTML 和 CSS 如下: HTML
<div className="loginArea">
<p>Account Login</p>
<div className="inputBoxes">
<div>
<input type="text" placeholder="Username" />
<input type="password" placeholder="Password" />
</div>
<div>
<p>Sign In</p>
</div>
</div>
</div>
CSS
.loginArea {
margin: auto;
padding-top: 8%;
display: flex;
flex-direction: column;
height: 100%;
max-width: 400px;
justify-content: center;
}
.inputBoxes {
display: flex;
flex-direction: column;
justify-content: center;
border-radius: 15px;
background-color: blue;
}
.inputBoxes div {
display: flex;
justify-content: center;
}
input {
flex-grow: 1;
border: none;
}
我的目标是根据输入/登录按钮的形状来实现此输入区域的样式,就像一个带圆角的矩形一样。
我遇到的问题有两个:
我似乎无法将输入区域的大小限制为父容器。它们在父 div 之外运行。
我似乎无法让输入区域接受父容器的受限边界半径。
我是否必须为圆形边框单独设置每个元素的样式,以及如何将用户名和密码区域限制为父 div 的宽度?
如果有“更好”的方法,我愿意接受建议。
解决方案
由于您已经在使用 flexbox,因此输入元素的大小似乎可以正确地放入父元素的范围内,没有任何问题。
关于您的第二个问题,添加overflow: hidden
到元素.inputBoxes
将起作用。
请参阅下面的概念验证:
body {
background-color: #ccc;
}
.loginArea {
margin: auto;
padding-top: 8%;
display: flex;
flex-direction: column;
height: 100%;
max-width: 400px;
justify-content: center;
}
.inputBoxes {
display: flex;
flex-direction: column;
justify-content: center;
border-radius: 15px;
background-color: blue;
overflow: hidden;
}
.inputBoxes div {
display: flex;
justify-content: center;
}
input {
flex-grow: 1;
border: none;
height: 35px; /* Just for demo */
}
<div class="loginArea">
<p>Account Login</p>
<div class="inputBoxes">
<div>
<input type="text" placeholder="Username" />
<input type="password" placeholder="Password" />
</div>
<div>
<p>Sign In</p>
</div>
</div>
</div>
推荐阅读
- powershell - 如何在 PowerShell 中转换字符串日期?
- kubernetes - 我们如何跟踪配置映射的变化?
- scala - Zeebe 取消部署的实例
- amazon-s3 - 无法从 AWS EMR 中的 Flink 访问 s3 文件
- javascript - 画中画和全屏在一起 - API 只能由用户手势启动
- c# - 在 .net3.5 和 .net4.0 上创建兼容的 c# .dll
- rest - 在 curl GET 请求中对多个请求参数获取空指针异常
- reactjs - 如何使用 react-native-svg 防止旋转形状上的翘曲/歪斜?
- php - 使用 Angular 8 将文件发布到 Laravel 服务器的正确方法
- java - 使用 MQ JMS 连接到 IBM MQ 时出现 MQRC_NOT_AUTHORIZED 错误