What is causing the input boxes to exceed their container boundaries so drastically?

My plan was to organize 4 input text boxes in 4 equal columns on a single row of the form. Using Bootstrap's grid column classes, I set col--3 for medium and large screens for those four inputs. For small and extra-small sizes, I designated them as col--12 so that each input occupies its own row. However, my supervisor wanted these input boxes to be smaller. To accommodate this, I added an offset class to the inputs and reduced their column span to 6 columns, ensuring they were centered correctly.

This adjustment unfortunately affected the layout on small screens, resulting in only two inputs per row with the other two on a separate row.

/* adjusting buttons*/

#button-wrapper {
  width: 40%;
  min-width: 200px;
  margin: 0 auto;
}

#ebook-download-button {
  margin: auto 0.5em;
}

.inner {
  margin: 0 auto 0 auto;
  width: 150px;
  padding: 0;
  /* center the block element*/
}

img {
  min-width: 100%;
}

input {
  height: 60%;
  margin: 0px;
}


/* making square elements*/

.square-elem {
  border-radius: 0px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<body>



  <form id="registration-form" class="">
    <!--<div class="col-md-12 col-sm-12">-->
    <div class="row">
      <div class="col-lg-3 col-md-3 col-sm-6 col-sm-offset-3 col-xs-6 col-xs-offset-3 ">
        <div class="form-group">
          <input type="input" class="form-control square-elem" id="first-name" placeholder="First Name">
        </div>
      </div>

      <div class="col-lg-3 col-md-3 col-sm-6 col-sm-offset-3 col-xs-6 col-xs-offset-3">
        <div class="form-group">
          <input type="input" class="form-control square-elem" id="last-name" placeholder="Last Name">
        </div>
      </div>

      <div class="col-lg-3 col-md-3 col-sm-6 col-sm-offset-3 col-xs-6 col-xs-offset-3">
        <div class="form-group">
          <input type="input" class="form-control square-elem" id="company" placeholder="Company">
        </div>
      </div>

      <div class="col-lg-3 col-md-3 col-sm-6 col-sm-offset-3 col-xs-6 col-xs-offset-3">
        <div class="form-group">
          <input type="input" class="form-control square-elem" id="email" placeholder="Email">
        </div>
      </div>
    </div>
    <div class="row">
      <div id="button-wrapper" style="">
        <div id="ebook-download-button" class="col-md-12 col-sm-12 col-xs-12 text-center">
          <a href="#" role="button" class="btn btn-danger btn-download form-control square-elem" value=""> DOWNLOAD EBOOK </a>
        </div>
      </div>
    </div>
    <!-- </div>
 -->
  </form>


</body>

For reference, here is the JSFiddle(Drag the frame) where you can see the issue clearly. The desired output should have all four inputs aligned side by side in one row. What could be causing this unexpected behavior?

Answer №1

If you're still experiencing the offset issue on larger screens, consider reversing the offset for each of the other col-classes by assigning col-md-offset-0 to the divs where offset was specified for smaller devices.

/* customized button styles */

#button-wrapper {
  width: 40%;
  min-width: 200px;
  margin: 0 auto;
}

#ebook-download-button {
  margin: auto 0.5em;
}

.inner {
  margin: 0 auto 0 auto;
  width: 150px;
  padding: 0;
  /* center the block element */
}

img {
  min-width: 100%;
}

input {
  height: 60%;
  margin: 0px;
}


/* square boxes */

.square-elem {
  border-radius: 0px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<body>

  <form id="registration-form" class="">
    <div class="row">
      <div class="col-lg-3 col-md-3 col-md-offset-0 col-sm-6 col-sm-offset-3 col-xs-6 col-xs-offset-3 ">
        <div class="form-group">
          <input type="input" class="form-control square-elem" id="first-name" placeholder="First Name">
        </div>
      </div>

      <div class="col-lg-3 col-md-3 col-md-offset-0 col-sm-6 col-sm-offset-3 col-xs-6 col-xs-offset-3">
        <div class="form-group">
          <input type="input" class="form-control square-elem" id="last-name" placeholder="Last Name">
        </div>
      </div>

      <div class="col-lg-3 col-md-3 col-sm-6 col-md-offset-0 col-sm-offset-3 col-xs-6 col-xs-offset-3">
        <div class="form-group">
          <input type="input" class="form-control square-elem" id="company" placeholder="Company">
        </div>
      </div>

      <div class="col-lg-3 col-md-3 col-sm-6 col-md-offset-0 col-sm-offset-3 col-xs-6 col-xs-offset-3">
        <div class="form-group">
          <input type="input" class="form-control square-elem" id="email" placeholder="Email">
        </div>
      </div>
    </div>
    <div class="row">
      <div id="button-wrapper" style="">
        <div id="ebook-download-button" class="col-md-12 col-sm-12 col-xs-12 text-center">
          <a href="#" role="button" class="btn btn-danger btn-download form-control square-elem" value=""> DOWNLOAD EBOOK </a>
        </div>
      </div>
    </div>
  </form>
</body>

Answer №2

the col-sm-offset-3 and col-xs-offset-3 classes are used to 'push' columns by 3 column widths, resulting in a margin-left equal to 3 column widths for the inputs.

For more information, visit http://getbootstrap.com/css/#grid-offsetting

To resolve any issues, simply remove these classes and everything should function correctly.

Check out the example on this fiddle link or view the snippet below


        /*Main box*/
        div #ebook-registration-box {
          border: 2px solid #d3d3d3;
          padding: 10px;
          margin: 10px auto;
        }

        /* button modification */
        #button-wrapper {
          width: 40%;
          min-width: 200px;
          margin: 0 auto;
        }

        #ebook-download-button {
          margin: auto 0.5em;
        }

        .inner {
          margin: 0 auto 0 auto;
          width: 150px;
          padding: 0;
          /* center the block element */
        }

        /* fixed height for responsive images (does not work) */
        img {
          min-width: 100%;
        }

        input {
          height: 60%;
          margin: 0px;
        }

        /* square boxes */
        .square-elem {
          border-radius: 0px;  
        }
      
    

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

        <div id="ebook-registration-box" class="row">
          <div class="col-md-12" >
            
            <div id="registration-header" class="row">
              <div class="col-md-12">
                <p class="text-center">
                  Register to download the device launch guide
                </p>
              </div>
            </div>
           
            <form id="registration-form" class="" >
             
              <div class="row">
                <div class="col-lg-3 col-md-3 col-sm-6 col-xs-6 ">
                  <div class="form-group">
                    <input type="input" class="form-control square-elem" id="first-name" placeholder="First Name">
                  </div>
                </div>
                
                <div class="col-lg-3 col-md-3 col-sm-6 col-xs-6 ">
                  <div class="form-group">
                    <input type="input" class="form-control square-elem" id="last-name" placeholder="Last Name">
                  </div>
                </div>
              
                <div class="col-lg-3 col-md-3 col-sm-6 col-xs-6 ">
                  <div class="form-group">
                    <input type="input" class="form-control square-elem" id="company" placeholder="Company">
                  </div>
                </div>
              
                <div class="col-lg-3 col-md-3 col-sm-6 col-xs-6">
                  <div class="form-group">
                    <input type="input" class="form-control square-elem" id="email" placeholder="Email">  
                  </div>
                </div>
              </div>
              
              <div class="row">
                <div id="button-wrapper" style="">
                  <div id="ebook-download-button" class="col-md-12 col-sm-12 col-xs-12 text-center">             
                    <a href="#" role="button" class="btn btn-danger btn-download form-control square-elem" value=""> DOWNLOAD EBOOK </a>
                  </div>
                </div>
              </div>
             
            </form>
          
          </div>
        
        </div>
      
    

Answer №3

Were you looking for this solution? To achieve the desired outcome, it's necessary to remove the offset for larger screen widths and reduce the offset for extra small screen widths.

#button-wrapper {
  width: 40%;
  min-width: 200px;
  margin: 0 auto;
}

#ebook-download-button {
  margin: auto 0.5em;
}

.inner {
  margin: 0 auto 0 auto;
  width: 150px;
  padding: 0;
  /* center the block element*/
}

img {
  min-width: 100%;
}

input {
  height: 60%;
  margin: 0px;
}


/* square boxes*/

.square-elem {
  border-radius: 0px;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="ebook-registration-box" class="row">
  <div class="col-md-12" > 
  
  <div id="registration-header" class="row">
     <div class="col-md-12">
        <p class="text-center">
           Register to download the device launch guide
        </p>
     </div>
  </div>
   <!-- 4 form elements--> 


 <form id="registration-form" class="" >
   <!--<div class="col-md-12 col-sm-12">-->
     <div class="row">
        <div class="col-lg-3 col-md-3 col-md-offset-0 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1 ">
<div class="form-group">
<input type="input" class="form-control square-elem" id="first-name" placeholder="First Name">
            </div>
        </div>
        
         <div class="col-lg-3 col-md-3 col-md-offset-0 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1">
           <div class="form-group">
            <input type="input" class="form-control square-elem" id="last-name" placeholder="Last Name">
   </div>
         </div>
      
         <div class="col-lg-3 col-md-3 col-md-offset-0 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1">
           <div class="form-group">
<input type="input" class="form-control square-elem" id="company" placeholder="Company">
   </div>
         </div>
      
        <div class="col-lg-3 col-md-3 col-md-offset-0 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1">
           <div class="form-group">
   <input type="input" class="form-control square-elem" id="email" placeholder="Email">  
           </div> 
        </div>
      </div>
      <div class="row">
        <div id="button-wrapper"  style="">
         <div id="ebook-download-button" class="col-md-12 col-sm-12 col-xs-12 text-center">             
          <a href="#" role="button" class="btn btn-danger btn-download form-control square-elem"  value=""> DOWNLOAD EBOOK </a>
         </div>
        </div>
      </div>  <!-- </div>-->
    
  </form>
    </div>   
 </div>

Answer №4

Give your <form> element a stylish look by applying the "form-inline" class for horizontal form presentation.

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

Is there a way to instruct the code to select between two variables and align their values?

I have encountered a challenge while working on a unit test. The website I am testing is dynamic, causing the CSS Selector and xpath to frequently change. As a solution, I came up with the idea of using both CSS and xpath to retrieve the same text. Curren ...

Leveraging jQuery within a dynamically loaded div

I am attempting to implement some jQuery on a page that is loaded into a div using the .load() function. The PHP code loaded into the div contains a hidden section that slides out when a link is clicked. However, I am facing an issue where the div slides b ...

Creating a collapsible accordion feature with jQuery using a specific HTML layout: wanna learn how?

I am looking to create an accordion effect with the structure provided below. The goal is to have the corresponding article toggle when clicking on .booklist>li>a, allowing only one article to be open at a time. Can someone assist me with writing thi ...

Attempting to sort through elements in JavaScript

I'm looking to filter specific films based on choices made in the dropdown menus below. <select id="filmDropdown"> <option value="0">All Films</option> <option value="1">Film 1</option> <option ...

Please explain the display property used in Bootstrap input groups

I have been working on implementing a button that toggles the visibility of a datepicker when clicked. <a class="btn btn-primary btn-lg mr-5" href="../Stores/stalls.html">Check Current Operating Stalls </a> <div style="vertical-align: t ...

The HTML page is not responsive to the screen size of the mobile device

Check out my HTML code: <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Test</title> <style type= ...

The art of fluidly positioning elements in Bootstrap columns

My goal is to showcase objects in 3 columns using Bootstrap 4. However, when I implement the code provided, the objects are only displayed in a single column, as shown here: example of 1 column layout. What I actually want is for the objects to be arrange ...

An issue related to AngularJS and the injection of ui-bootstrap components has been encountered

I'm encountering an issue with injection errors in my code, and unfortunately, the debugger in Firefox isn't providing much help. Here are snippets of the code: This is the Controller file causing the error: App.controller('ModalInstanceCt ...

Setting the [required] attribute dynamically on mat-select in Angular 6

I'm working on an Angular v6 app where I need to display a drop-down and make it required based on a boolean value that is set by a checkbox. Here's a snippet of the template code (initially, includeModelVersion is set to false): <mat-checkbo ...

"Step-by-step guide on placing an order for the button

I am currently working with material-ui and encountering a roadblock. My goal is to design a homepage for a dashboard where the various services are listed. I am attempting to organize these 6 buttons into 2 rows and 3 columns, totaling 6 buttons in all. A ...

Elements on the page are being truncated beyond the visible viewport

Encountering an issue with a web page I'm currently developing that is proving challenging to explain. The problem occurs when the page is viewed in a small browser window and cuts off when scrolling horizontally to content outside of the viewport. Wh ...

Utilizing a StyledComponents theme within a Component

When creating a style called Link, the theme is contained inside of this.props. How can the theme be extracted from props and passed into the Link styled component? Error: ReferenceError - theme is not defined import React from 'react'; impo ...

Error: Codeigniter AJAX endpoint cannot be located

While working on an ajax call in CodeIgniter using the .ajax function, I encountered a problem. My controller is named Control and it has a function called Login. When I try to execute this code: $.ajax({ url: "Connection/Login", type: " ...

What is the best way to retrieve the information stored in an object?

let items = { 1001: {item: 'Chocolates', price: 10, quantity: 10}, 1002: {item: 'Biscuits', price: 10, quantity: 10}, 1003: {item: 'Bread', price: 20, quantity: 5}, 1004: {item: 'Milk', price: 25, quantity: 5}, 1005: ...

Initiating the onclick event for Input/Form

<form method="POST" onsubmit="return false;"> ... <input type="submit" name="button" value="Login" onclick="require('file.js').submitForm(this.form);"> ... </form> Is there a way to trigger the onclick event of this INPUT eleme ...

Transmitting the User's Geographic Location and IP Address Securely in a Hidden Input Field

I'm looking to enhance my HTML form by retrieving the user's IP address and country when they submit the form. How can I achieve this in a way that hides the information from the user? Are there any specific elements or code additions I need to ...

Full-screen and auto-cropping capabilities are featured in the Bootstrap 4 carousel design

Is there a way to make full-width images in the bootstrap 4 carousel cropped based on position: center, background: cover to prevent scrolling issues? I attempted to follow advice from this webpage but encountered stretching and scroll-bar problems with d ...

Guide on creating an autonomous select-all checkbox to show table columns

How can I create checkboxes with a "Select all" option and the following functionality: Check one or more checkboxes to show specific table columns. Uncheck them to hide the columns (toggle). Select the "Select all" checkbox to display all table columns. ...

Does strip_tags() have vulnerabilities to scripting attacks?

Has there been any known XSS or other attack that can bypass the following code snippet? $content = "some HTML code"; $content = strip_tags($content); echo $content; This function does not modify any attributes on the tags that you allow using ...

What is the best way to determine the quantity of identical items in the django templating language?

My goal is to create a table that organizes items by type, all retrieved from my database. Currently, I can display the items and their corresponding types without any issues in a table format. However, I want to avoid repeating the same type multiple time ...