gpt4 book ai didi

html - 在文本输入中放置美元符号

转载 作者:行者123 更新时间:2023-11-28 10:30:32 25 4
gpt4 key购买 nike

我想在文本框的开头保留美元符号。我可以使用以下代码实现此目的。

它可以在 chrome 和 IE 中找到。美元符号位于 Firefox 中的标签旁边。我该如何解决这个问题?为了将美元符号与文本对齐,我使用了 top 2px。有没有办法改进 css 代码。

.input-symbol-dollar:after {
color: #37424a !important;
content: "$";
font-size: 16px !important;
font-weight: 400;
left: 10px;
position: absolute;
top: 2px;
}

.input-symbol-dollar {
position: relative;
}

.abc-input {
border: 2px solid #c9c9c9;
box-shadow: none;
color: #6b6f72;
font-size: 0.9375rem;
text-transform: none;
width: 100%;
color: #37424a !important;
font-family: "Roboto Regular", sans-serif;
font-size: 16px !important;
font-weight: 400;
height: 42px !important;
padding-left: 17px !important;
display: inline-block !important;
}

label {
color: #37424a;
display: inline-block;
font-family: "Roboto Bold", sans-serif;
font-size: 15px;
font-weight: 700;
margin-bottom: 8px;
}
<label for="abcInput" class="abc-label">lable filed </label>
<span class="input-symbol-dollar">
<input type="text" id="abcInput" tabindex="0" name="abc" class="abc-input " placeholder="0.00"></span>

https://jsfiddle.net/8jdek3zt/5/

最佳答案

看起来你的例子中有很多不必要的代码。

这是一个适用于 Chrome、Firefox 和 IE 的简化版本(未在 Safari 中测试)。

span {
display: inline-block;
position: relative;
}

input {
border: 2px solid #c9c9c9;
box-shadow: none;
font-family: "Roboto Regular", sans-serif;
font-size: 1.5em;
height: 42px;
padding-left: 20px;
}

span::before {
content: "$";
font-family: "Roboto Regular", sans-serif;
font-size: 1.5em;
position: absolute;
left: 5px;
top: 50%;
transform: translateY(-50%);
}
<span>
<input placeholder="0.00">
</span>

这里对伪元素的垂直居中方法做一下解释:

关于html - 在文本输入中放置美元符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45244518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com