仅使用CSS的输入字段的一部分
16lz
2021-01-22
I have an input field, and inside it on the right side there is a string that displays information to the user.
我有一个输入字段,在右侧有一个字符串,向用户显示信息。
<div class="my_div_class">
<input class="my_input_class" type="text" placeholder="Search">
<span class="my_span_class">6000 available</span>
</div>
Using position relative and absolute, I places the span inside the input field.
使用position relative和absolute,我将span放在输入字段中。
However, if the user types a long query, the text will be under the span text.
但是,如果用户键入长查询,则文本将位于范围文本下。
Is there a way to force the input field to do the horizontal scroll when the user reaches a point before the right margin, ideally without using javascript?
有没有办法强制输入字段在用户到达右边距之前的点时进行水平滚动,理想情况下不使用javascript?
2 个解决方案
#1
1
You can add some padding-right
to the input box.
您可以在输入框中添加一些填充权限。
.my_div_class {
position: relative;
width: 200px;
}
.my_input_class {
width: 100%;
padding-right: 100px;
box-sizing: border-box;
}
.my_span_class {
position: absolute;
right: 0;
top: 0;
}
<div class="my_div_class">
<input class="my_input_class" type="text" placeholder="Search">
<span class="my_span_class">6000 available</span>
</div>
更多相关文章
- 用于检查用户名可用性的Javascript帖子无效
- 使用jquery和php手动在数据库中增加一个字段[复制]
- PHP中对用户密码进行加密
- 如何在PHP中自动设置用户的语言环境?
- 存储用户所需语言的最佳方式
- Pubsub与Node.js和Socket.io为个人用户
- 如何使用用户名作为子域名创建子域?
- 更新日期字段时为空 - MySQL PHP
- jQuery PHP:检查用户名是否已经存在