What causes the content area of my <input> element to extend beyond the boundaries of its parent <span> element?

Please Note: I've been working on extracting code from a WordPress environment running the Salient theme. As of now, I haven't been able to simplify the issue to its core form. There is a possibility that I might figure it out myself, but I welcome any feedback from the community throughout this process. Hopefully, this question will provide valuable insights.

The problem I'm facing can be outlined as follows:


I am striving for better control over how my content appears on the screen, and it seems like there's something about CSS that I'm not grasping. I experimented with the "box-sizing: border box" property to include padding and borders in the total width calculation of an element. I have shared links below to illustrate the state of the input and span elements:

Highlight of Input Element in Chrome Devtools

Content Area of Span Element in Chrome Devtools

My assumption is that the box-sizing approach isn't effective due to a margin-related concern. It's likely that the "margin-left" property has impacted the overall content area, causing the content to extend beyond the span element boundaries. However, my goal is to confine the input element within the span element.

Additions to HTML and CSS courtesy of Lucien Dubois

* { 
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box; }

        .contact-fields input, textarea{
          margin-left: 12px;
        }

        .wpcf7-form-control-wrap {
          display: block !important;
          position: relative;
        }

        div, span, h5, p {
          vertical-align: baseline; 
          font-family: inherit; 
          font-weight: inherit; 
          font-style: inherit; 
          font-size: 100%; 
          outline: 0; 
          padding: 0; 
          margin-right: 0; 
          border: 0
        }

        h5
        {
          font-family: Raleway;
          line-height: 16px;
          margin-bottom: 7px;
          color: #444; 
          letter-spacing: 0px;
          font-weight: 600;
        }

        .form-label {
          clear: both;
          font-size: 20px
        }

        h5 {
          vertical-align: baseline; 
          font-style: inherit; 
          outline: 0; 
          padding: 0; 
          margin-top: 0;
          margin-right: 0;
          margin-left: 0;
          border: 0
        }

        .first-name,  .last-name {
            display: inline-block;
            width: 40%;
            margin-right: 9px;
        }

        .first-name input, .last-name input {
          width: 62%;
        }

        input {
            margin-bottom: 20px;
            margin-top: 5px;
        }
      
<div class="contact-fields">
        <div class="name-section">
          <div class="first-name">
            <h5 class="form-label"> First Name:</h5>
            <p>      
              <span class="wpcf7-form-control-wrap fname">
                <input type="text" 
                      name="fname" 
                      value="" 
                      size="40" 
                      maxlength="50" 
                      class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required input-field" 
                      aria-required="true" 
                      aria-invalid="false">
              </span>
            </p>
          </div>
          <div class="last-name">
            <h5 class="form-label"> Surname:</h5>
              <p>      
                <span class="wpcf7-form-control-wrap lname">
                  <input type="text" 
                         name="lname" 
                         value="" 
                         size="40" 
                         maxlength="50" 
                         class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required input-field" 
                         aria-required="true" 
                         aria-invalid="false"></span>
              </p>
          </div>
        </div>
      </div>

Answer №1

One way to solve this is by incorporating the min and max properties into your input field:

input {
    min-width: 100%;
    max-width: 100%;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Show the div in the right position for both desktop and mobile screens, utilize an accordion or consider shifting the div

My webpage is designed using bootstrap 4 and showcases images of our team members along with accordion functionality to display bios upon clicking the image. On a desktop screen, everything functions smoothly with four images of team members displayed in ...

Issues with zoom functionality not functioning properly within IE11

I am currently developing an application with Angular that is designed to be compatible with tablets and touch-enabled devices. One of the key features I want to implement is the ability for users to zoom/scale up the app, especially for those with visual ...

Opencart admin URL customizer (Eliminate index.php?route="")

Is there a way to conceal the index.php?route="" & user_token="" links on my Opencart admin page? I would like it to display as something like admin/dashboard instead of admin/index.php?route=common/dashboard&user_token="" ...

Designing the autocomplete dropdown feature in Bootstrap UI

I'm currently developing an app that is utilizing AngularJS and Bootstrap, with the assistance of Bootstrap UI. Specifically, I am working on implementing the typeahead feature. However, I am facing a challenge in trying to ensure that the dropdown li ...

Transitioning React Hover Navbar Design

I'm currently revamping a click-to-open navbar into a hover bar for a new project. I have successfully implemented the onMouseEnter and onMouseLeave functions, allowing the navbar to open and close on mouse hover. However, I am facing an issue with ad ...

Aligning a div in relation to the background image

I am seeking guidance on how to center a Div Box and make it responsive relative to the background image. The div box should be contained within the white box, similar to the example shown here: body{ font-family: 'Roboto Mono', monospace; ...

Using AngularJS to create a form and showcase JSON information

My code is below: PizzaStore.html: <!DOCTYPE html> <html ng-app="PizzaApp"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Delicious pizza for all!</title> ...

Creative Text Container CSS Styling

Check out this website for the container I want to replicate: container This is the specific textbox: Here's how mine currently appears: I analyzed their css file and examined their html source code. I isolated the section of html and css related t ...

Enhancing Bootstrap with VueJS for better component ordering

I've been struggling with Vue components in Bootstrap lately. I am attempting to create collapsible Bootstrap content in Vue, and here is the current code: HTML <div class="col-sm main-content" id="main-content"> <p&g ...

Changing the color of the selected item in a Jquery Mobile ListView

I have a dynamic list that triggers a JavaScript function using the onclick event. However, I am struggling to change the color of the selected item in the list. Here is an example of the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional ...

The <select> element is experiencing compatibility issues with the camera controls in ThreeJs

I have been developing a ThreeJs application that includes a dropdown menu for user selections, resulting in changes to the displayed objects. However, I have encountered an issue where using the html select tag with camera controls (such as Trackball or ...

In my ejs file, I need to input a name and then process it in my post request

I am working on an ejs file where I need the user to input their username into a form. I will then use this username in a .get request to perform certain logic. However, I am encountering an issue where the username is showing up as undefined. Here is a s ...

Creating a login form using HTML, PHP, and MySQL: A step-by-step guide

UPDATE [13.10.16] After revisiting a previous question of mine on stackoverflow that has low reputation, I realized the reasons behind it and decided to update it to make it more relevant. When I initially asked this question, I was attempting to create ...

Tips for shutting down an open section within a jQuery Accordion?

I am having trouble closing the active panel using jQuery. The rest of my code is functioning perfectly, but for some reason, I can't get the active panel to close. Currently, the code is working correctly in that only one panel can be open at a time ...

Encountering an unexpected token in Javascript when using conditionals

I am currently attempting to integrate a JavaScript condition within a listed order, containing two radio buttons that need to be checked in order to progress to the following list based on the selection. <li data-input-trigger> <label class="fs- ...

What is causing onbeforeunload to consistently display a dialog box?

I'm facing an issue where my javascript code displays a confirmation dialog even when there is no unsaved data. I have simplified the problem to this bare minimum: window.addEventListener("beforeunload", (e) => { e.returnValue = null; retu ...

Steps to dynamically display or conceal a DIV using Bootstrap 5

I am facing an issue with a navbar that has buttons to reveal hidden divs underneath. <a data-bs-toggle="offcanvas" href="#select" role="button" aria-controls="select"></a> <div id="select" c ...

Enhance the functionality of selectize.js by incorporating select options through ajax

I'm currently working on implementing options to a select box using AJAX and selectize.js. When not using selectize.js, everything functions correctly. The two select boxes are interconnected so that when one is updated, the values in the other select ...

Conceal the button briefly when clicked

How can I disable a button on click for a few seconds, show an image during that time, and then hide the image and display the button again? HTML: <input type="submit" value="Submit" onclick="validate();" name="myButton" id="myButton"> <img st ...

Flex container scrollable element not functioning consistently between different browsers

Today, I've spent most of my time experimenting with various solutions but I'm facing difficulty making them work consistently across different browsers. My goal is to have 2 sections within a fixed div: the first section with a set height and t ...