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

Trouble getting a responsive text input to stay within a Form's boundaries

I’m a beginner Web Developer who is trying to include a responsive text input in the simple website I am building. After setting the appropriate width and max-width, I noticed the input bar was not staying within the boundaries of its form container as the page got narrower. After some research and troubleshooting, I determined that the issue is being caused by the input bar’s left and right margins.

With the proper box-sizing setting and no margins, the responsiveness behaves as I’d expect. The moment I add the margins, it starts to go out of bounds. Any idea what could be causing this? I’ve been struggling to find a solution beyond my box-sizing settings and really appreciate the help.

        <section id="newsletter">
            <h2>Join our newsletter</h2>
            <form action="" id="inputBar">
                <input type="text" name="email" id="email" value="Enter E-mail Address">
                <input type="button" value="Submit" class="btn">
            </form>
        </section>
#inputBar {
    border: 1px solid black;
}

.btn {
    color: white;
    font-size: 24px;
    font-weight: 100;
    background-color: #1C3F74;
    border-radius: 43.5px;
    width: 220px;
    padding: 20px 15px;
    border: none;
}

#email {
    box-sizing: border-box;
    font-weight: lighter;
    font-size: 26px;
    background-color: #E5E5E5;
    border-radius: 43.5px;
    width: 100%;
    max-width: 680px;
    padding: 20px 35px;
    border: none;
    margin: 1em;
}

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

>Solution :

You can try this :

#inputBar 
        {
                 border: 1px solid black;
                 padding:15px;
        }

        .btn {
            color: white;
            font-size: 24px;
            font-weight: 100;
            background-color: #1C3F74;
            border-radius: 43.5px;
            width: 220px;
            padding: 20px 15px;
            border: none;
        }

        #email {
            box-sizing: border-box;
            font-weight: lighter;
            font-size:26px;
            background-color: #E5E5E5;
            border-radius: 43.5px;
            width: 100%;
            max-width:680px;
            padding:20px 35px;
            border:none;
            margin:0 1em 1em 0;
        }
<section id="newsletter">
            <h2>Join our newsletter</h2>
            <form action="" id="inputBar">
                <input type="text" name="email" id="email" value="Enter E-mail Address">
                <input type="button" value="Submit" class="btn">
            </form>
        </section>
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