html - 如何将子文本元素与输入文本元素的底部对齐

标签 html css input text alignment

我创建了一个 HTML 元素供用户输入浮点值,并将输入分成两个输入元素,一个用于整数,另一个用于小数。我在两个输入文本元素之间包含了一个小数点作为文本元素,但它没有与两个输入元素的底部对齐,我不知道如何解决这个问题。这是我的代码片段:

#whole {
  text-align: center;
  width: 25%;
  margin-top: 10px;
  box-sizing: border-box;
  -webkit-box-sizing:border-box;
  -moz-box-sizing: border-box;
}
#decimal {
  text-align: center;
  width: 45%;
  margin-top: 10px;
  box-sizing: border-box;
  -webkit-box-sizing:border-box;
  -moz-box-sizing: border-box;
}
#decimal_point {
  vertical-align: bottom;  /*align decimal point to bottom*/
}
<div>
       <input type=text maxlength=1 id=whole name=whole value=>
       <span id=decimal_point> . </span>
       <input type=text maxlength=3 id=decimal name=decimal value=>
    </div>

我更新了代码并遇到了这个问题:
enter image description here

最佳答案

您可以使用 CSS vertical-align span 上的属性(property)元素。像这样:

.decimal-box span{
    vertical-align: bottom;  /*align decimal point to bottom*/
    line-height: 0.7; /* If desired, set line-height to push decimal point further down*/
}

#whole {
  text-align: center;
  width: 25%;
  margin-top: 10px;
  box-sizing: border-box;
  -webkit-box-sizing:border-box;
  -moz-box-sizing: border-box;
}

#decimal {
  text-align: center;
  width: 45%;
  margin-top: 10px;
  box-sizing: border-box;
  -webkit-box-sizing:border-box;
  -moz-box-sizing: border-box;
}
<div class="decimal-box">
     <input type="text" maxlength=1 id="whole" name="whole" value="">
     <span> . </span>
     <input type="text" maxlength="3" id="decimal" name="decimal" value="">
 </div>

关于html - 如何将子文本元素与输入文本元素的底部对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59940126/

相关文章:

JavaScript 三 Angular 函数问题

javascript - 将textarea的文本复制到带有换行符的div中

css - 脱离 CSS 的抽象

javascript - 在数据库中插入经纬度

html - 如何更改 <select> 中 <option> 的文本颜色?

html - 为什么我的 div 没有放置 "inside"包装器 div?

javascript - bootstrap 轮播不同尺寸

vb.net - 在 VB.net 中逐行读取文本框的最佳方法

java - 程序未读取第一个字符串输入

iOS Safari 输入属性大写?