One reason for the issue is that inline-block elements create extra spacing between them. This can be avoided by using float:left
or adding a parent element with font-size:0
. Another solution is to use box-sizing:border-box
, which applies padding from inside the element.
For example, if an element has a width of 100%
and a padding of 15px
, the total width will be 100% + 15px when using box-sizing:border-box
.
In this demonstration, the border style has been changed to outset
.
Check out the demo here - http://example.com/demo
body {
background-color: blue;
}
div {
font-size:0;
}
.txt {
display: inline-block;
width: 80%;
font-size: 2em;
outline: none;
padding: 15px;
margin:0;
box-sizing:border-box;
}
.btn {
display: inline-block;
margin: 0;
outline: 0 none;
padding: 0;
width: 20%;
box-sizing:border-box;
}
<div>
<input class="txt" type="text" name="name" />
<button class="btn">Submit</button>
</div>