In my example i have a wrapper div which has position: relative
The input field has a width of 100% and the button was placed on the right end of the input field. For this i used position: absolute
The button should have the same height as the input. Why is the button a little bit bigger as the input field? Is there any css statement to fix this issue?
.wrapper {
position: relative;
max-width: 400px;
}
.wrapper textarea {
background-color: white;
border: 1px solid #666;
color: #999;
border-radius: 7px;
padding: 9px 10px;
width: 100%;
display: inline-block;
position: relative;
box-sizing: border-box;
font-size: 14px;
font-weight: normal;
font-family: Roboto;
}
.wrapper button[type=submit] {
position: absolute;
right: 0;
top: 0;
min-height: 37px;
height: 100%;
width: 43px;
line-height: inherit !important;
border: unset;
background: red;
border-radius: 0 6px 6px 0;
}
<div class="wrapper">
<textarea type="text" placeholder="Placeholder"></textarea>
<button type="submit"><i class="fas fa-search"></i></button>
</div>
3
Answers
vertical-align: top;
remove bottom padding of textareaChange your textarea to an input Tag and give it a height
If you set the wrapper to
display: grid
, the default behavior is for the grid children to stretch along both axes.