When a div is placed behind another div, the text in both div elements aligns.
.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>
Replacing the div with class top
with an input causes the text to be aligned incorrectly by 1px, even though the border remains aligned properly.
.wrapper {
box-sizing: border-box;
padding: 0;
margin: 0;
outline: none;
padding-right: 20px;
}
.box {
height: 34px;
width: 130px;
padding: 6px 12px;
font-family: Verdana;
font-size: 24px;
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">
<input type="text" value="20-123" class="box top">
<div class="box underlayer">20-123-20</div>
</div>
I'm struggling to understand it. Can someone explain and suggest how to fix this issue?