html - 使用标签元素显示带有内部标签的输入 - 输入宽度超过 Firefox 中的标签

标签 html css firefox

我试图在文本输入中放置一个跨度,以在其前面加上“$”字符,以表示美元金额。

为此,我使用了一个标签元素,其中包含“$”跨度以及设置为 100% 宽度的实际输入。标签元素的样式看起来像一个文本框。

这在 Chrome 和 IE 中运行良好,但在 Firefox 中似乎在输入上设置 100% 宽度并没有考虑跨度,因此超出了实际标签元素的边界:

screenshot of issue in Firefox

代码示例:

.container { width: 400px; }
.w70 { width: 70px; }

.input-with-label {
   border: 1px solid #D9D9D9;
   display: flex;
   align-items: center;
   background-color: #fff;
}

.input-with-label.-dollar-amount > input[type='text'] {
   text-align: right;
   font-weight: 600;
   
}

.input-with-label > input[type='text'] {
   margin: 0;
   border: none;
   width: 100%;
}

.input-with-label > .input-label {
   padding-left: 3px;
   font-size: 10px;
   border: none;
}
<div class="container">
  <label class="input-with-label -dollar-amount w70">
    <span class="input-label">$</span>
    <input type="text" value="0.00" />
  </label>
</div>

最佳答案

min-width:0 设置为输入并通过 flex:1 使其使用所有可用宽度不能解决问题吗?

.container { width: 400px; }
.w70 { width: 70px; }

.input-with-label {
   border: 1px solid #D9D9D9;
   display: flex;
   align-items: center;
   background-color: #fff;
}

.input-with-label.-dollar-amount > input[type='text'] {
   text-align: right;
   font-weight: 600;
   
}

.input-with-label > input[type='text'] {
   margin: 0;
   border: none;
   min-width: 0;
   flex: 1;
}

.input-with-label > .input-label {
   padding-left: 3px;
   font-size: 10px;
   border: none;
}
<div class="container">
  <label class="input-with-label -dollar-amount w70">
    <span class="input-label">$</span>
    <input type="text" value="0.00" />
  </label>
</div>

关于html - 使用标签元素显示带有内部标签的输入 - 输入宽度超过 Firefox 中的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46413009/

相关文章:

html - 为 3 个 div 设置固定高度

javascript - 选择数组javascript的一部分

jQuery 下拉菜单,子菜单在内部打开而不是在侧面

firefox - Firefox 中查看>页面样式的目的是什么?

firefox - WebRTC 的 ReplaceTrack 在 Firefox 中突然无法工作

html - 防止显示 :table-cell from stretching 的 div

php - Twitter Bootstrap 缩略图不是并排的

css - 没有声明位置的固定元素继承静态位置?

HTML/CSS - 格式化从属元素

javascript - jGravity(jQuery 插件)在 Firefox 中无法拖动