Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

HTML CSS Input exceeds width

I cannot seem to find a solution to my issue, which is why I’m here.

I cannot, for the life of me, make the input remain within its parent div.
This following code is an isolated small-scale replication of the issue, just to make sure there’s nothing else affecting it.

If you use the following code, you’ll see that the inputs side by side, somehow are wider than their owner.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.main-container
{
    width: 30%;
    background-color: grey;
    height: 50px;
    display: flex;
}

.inner-container
{
    width: 100%;
}

input
{
    width: 100%;
}
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<div class="main-container">
    <div class="inner-container">
        <input>
    </div>
    <div class="inner-container">
        <input>
    </div>
</div>

</body>
</html>

If anyone could please point to my mistake, I’d be extremely happy.

Thank you all in advance,
Matt

>Solution :

Add box-sizing: border-box;

   *{box-sizing: border-box;}
.main-container
{
    width: 30%;
    background-color: grey;
    height: 50px;
    display: flex;
}

.inner-container
{
    width: 100%;
}

input
{
    width: 100%;
}
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<div class="main-container">
    <div class="inner-container">
        <input>
    </div>
    <div class="inner-container">
        <input>
    </div>
</div>

</body>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading