将一个div放在另一个div后面时,bot div元素中的文本将对齐。
.wrapper {
box-sizing: border-box;
padding: 0;
margin: 0;
outline: none;
padding-right: 20px;
}
.box {
height: 34px;
width: 130px;
padding: 6px 12px;
font-size: 24px;
font-family: Verdana;
color: #555555;
background: rgba(255, 255, 255, 0) none;
border: 1px solid #cccccc;
border-radius: 4px;
}
.top {
z-index: 2;
position: relative;
}
.underlayer {
top: -48px;
z-index: 1;
position: relative;
background: rgba(255, 255, 255, 1);
color: #c8c8c8;
margin:0;
}
<div class="wrapper">
<div type="text" class="box top">20-123</div>
<div class="box underlayer">20-123-20</div>
</div>
当类为top
的div被替换为input时,文本将关闭1px,但边框仍然正确对齐。
一个二个一个一个
我不能把我的头周围。有人在这里解释它,并建议如何解决这个问题?
3条答案
按热度按时间cygmwpex1#
这是由于输入的处理方式造成的。input-element中的文本字段被拉伸以适应框的大小。在本例中为34px。因此修复方法是增加div的行高以匹配输入的34px。
fkvaft9z2#
您的字体有问题。衬层使用一种字体,另一种使用另一种字体。
我还添加了一个字体大小,并隐藏第二个框,这样您就可以移动底层的顶部位置,以匹配顶部的文本。
这可能不是最好的方式,但它的工作。
izj3ouym3#
你把
underlayer
从div
改为input
。它把第二个div的字体改为输入使用的字体。因为underlayer
的z轴较低,所以用户永远不会选择它,不,它不会产生任何危险。你还把第二个输入的显示设置为block
。不幸的是,我不知道最初为什么会发生,所以我无法解释。