I made a calculator using HTML, CSS and JavaScript. Everything is working fine but the input bar is slightly overflowing on the right side.
I tried aligning it to center and so many things, but nothing worked.
Here is my code (only the input part):
* {
margin: 0;
padding: 0;
}
body {
min-height: 100vh;
justify-content: center;
display: flex;
align-items: center;
}
.container {
width: 250px;
height: 400px;
background-color: antiquewhite;
padding: 20px;
border-radius: 1.5rem;
outline: 5px solid gray;
}
.container input {
width: 100%;
border-style: none;
height: 50px;
border-radius: 1rem;
outline: 2px solid;
font-size: 20px;
text-align: right;
padding-right: 10px;
}
<div class="container">
<!--Input-->
<div class="input">
<input type="text" placeholder="Write your equation here " value="" />
</div>
How can I get the input to fit within the container?
if an element is not defined as box-sizing: border-box
the width is not calculated with the padding. meaning it calculates 100% width and added 10px from the padding-right: 10px
* {
margin: 0;
padding: 0;
/* the change */
box-sizing: border-box;
}
body {
min-height: 100vh;
justify-content: center;
display: flex;
align-items: center;
}
.container {
width: 250px;
height: 400px;
background-color: antiquewhite;
padding: 20px;
border-radius: 1.5rem;
outline: 5px solid gray;
}
.container input {
width: 100%;
border-style: none;
height: 50px;
border-radius: 1rem;
outline: 2px solid;
font-size: 20px;
text-align: right;
padding-right: 10px;
}
<div class="container">
<!--Input-->
<div class="input">
<input type="text" placeholder="Write equation here" value="" />
</div>