html - 如何在html / css中输入字段的左上角放置标签
问题描述
请参考下图以供参考。我想要一种类似的表单,标签放在左上角的输入字段顶部。
图片:
提前致谢!
- - 更新 - -
我试过了,我能够将标签单独放在输入字段的顶部,但无法合并它。
这是它目前的样子:
<div class="form-group mt10">
<label for="inputName">Name <span class="reqField">*</span></label>
<input required type="text" class="form-control" id="inputName" placeholder="Name">
</div>
<div class="form-group">
<label for="inputCountry">Country</label>
<input type="text" class="form-control" id="inputCountry" placeholder="Country">
</div>
解决方案
这样的事情会有所帮助。
body.app-body {
background: #cecece;
}
.form-group {
border: 2px solid;
margin: 10px;
border-radius: 15px;
margin-top: 20px;
}
.form-group>label {
position: absolute;
top: 6px;
left: 20px;
padding: 5px 10px;
border-radius: 15px;
background: #fff;
}
.form-group>input {
border: none;
background: transparent;
}
<body class="app-body">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<form id="first_name">
<div class="form-group">
<label>First name</label>
<input type="text" class="form-control input-lg" />
</div>
</form>
</body>
推荐阅读
- sql - 获取过去 24 小时内每小时的记录数
- javascript - innerHtml +花括号的角度5问题
- python - 如何读取 .hdf5 数据文件作为卷积神经网络的输入?
- jquery - 获取特定行的 td 值,其中所有 tr 具有相同的类
- android - 单击图像并使用 Instagram 等操作打开缩放布局
- ios - Swift使用firebase在聊天中显示最后发送的消息
- mysql - 在Mysql中将字符串拆分为单个值
- git - 如何只公开私有 git 存储库的一个文件?
- java - 在任何具有当前光标而不使用内容提供程序的应用程序中显示字符串
- javascript - Office JS API:未触发 ItemChanged 事件,当前项目具有旧上下文