Switching between various quantities of inputs in each row using Bootstrap V3

My Bootstrap V3 form has a mix of rows with two inputs and rows with one input, as per the designer's request.

Check out my fiddle here: https://jsfiddle.net/06qk4wh4/

<div class="form-group  col-sm-12">
    <label class="control-label col-sm-2">
        Label 1
    </label>
    <div class="col-sm-10">
        <input type="text" class="form-control col-sm-12" />
    </div>
</div>
<div class="form-group col-sm-12 col-md-6">
    <label class="control-label col-sm-2 col-md-4">
        Label 2
    </label>
    <div class="col-sm-10 col-md-8">
      <input type="text" class="form-control col-sm-12" />
    </div>
</div>
<div class="form-group col-sm-12 col-md-6">
    <label class="control-label col-sm-2 col-md-4">
        Label 3
    </label>
    <div class="col-sm-10 col-md-8">
      <input type="text" class="form-control col-sm-12" />
    </div>
</div>
<div class="form-group col-md-12">
    <label class="control-label col-sm-2">
        Label 4
    </label>
    <div class="col-sm-10">
        <input type="text" class="form-control col-sm-12" />
    </div>
</div>

The issue arises in the row with two inputs, resulting in an alignment error (shown in red in the image below). When using col-sm-x, it works fine because it occupies the full width. However, when switching to col-md-x to display two inputs in one row, the "alignment error" occurs due to percentage calculation.

https://i.stack.imgur.com/0RKSp.png

Are there any simple solutions for this common problem? Your insights are much appreciated!

Answer №1

If you give this code a try, it may resolve the issue you're experiencing. I've included an additional row after your col-sm-12 div element.

<div class="form-group  col-sm-12">
    <div class="row">
        <label class="control-label col-sm-2">
            Label 1
        </label>
        <div class="col-sm-10">
            <input type="text" class="form-control" />
        </div>
    </div>
</div>
<div class="form-group col-sm-12 col-md-6">
    <div class="row">
        <label class="control-label col-sm-2 col-md-4">
            Label 2
        </label>
        <div class="col-sm-10 col-md-8">
            <input type="text" class="form-control" />
        </div>
    </div>

</div>
<div class="form-group col-sm-12 col-md-6">
    <div class="row">
        <label class="control-label col-sm-2 col-md-4">
            Label 3
        </label>
        <div class="col-sm-10 col-md-8">
            <input type="text" class="form-control" />
        </div>
    </div>
</div>
<div class="form-group col-md-12">
    <div class="row">
        <label class="control-label col-sm-2">
            Label 4
        </label>
        <div class="col-sm-10">
            <input type="text" class="form-control" />
        </div>
    </div>
</div>

Hopefully, this provides a solution to your problem :)

Richie

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

What is the best method for effectively organizing and storing DOM elements alongside their related objects?

In order to efficiently handle key input events for multiple textareas on the page, I have decided to create a TextareaState object to cache information related to each textarea. This includes data such as whether changes have been made and the previous co ...

"Skip the inbox clutter and access the compose page directly on Gmail, Yahoo, and

I was looking to create a unique hyperlink that would direct users to a compose page similar to Google Mail. Here is an example of what I tried: <li><a href="https://inbox.google.com/mail/?view=cm&fs=1&<a href="/cdn-cgi/l/email-protect ...

Which specific divs should I assign an ID to within the class?

Is there a way to apply the gray box style to specific divs instead of all of them? Should I include an id somewhere in the code? <!DOCTYPE html> <html> <head> <style> div { width: 320px; padding: 10px; border: 5px soli ...

When using the "Content-Disposition" header with the value "inline;filename=" + fileName, it does not necessarily guarantee that PDF files will be displayed directly

When a link is clicked, I want the PDF file to first show in a new tab as a preview before allowing users to download it. I researched and found advice suggesting that including these two headers would achieve this: Response.AddHeader("Content-Dispositio ...

The height and alignment of the <a> tag and <p> element vary within a flex container

Currently, I am in the process of constructing a bottom navigation bar for a blog page. This navigation bar will allow users to easily navigate between the last blog entry, the main blog home/index, and the upcoming post. However, when the user reaches the ...

Trouble with a basic Angular demonstration

After replicating an angular example from w3schools (found here), I encountered some issues with it not functioning correctly. Despite my efforts, the code appears to be accurate. Can anyone spot what might be going wrong? To provide more context, here is ...

Uncovering website content with Selenium: unlocking the mysterious origins of the text

Currently, I am utilizing Selenium and Python to scrape a website. My goal is to extract specific text from a particular page. Despite successfully navigating to the desired page, every attempt at using methods such as driver.find_elements_by_id(), driver. ...

Personalizing CSS classes in ASP.NET

In the project I'm currently developing, users will have the ability to customize the font color of header titles. These header titles are styled using values from a cssClass, which includes properties such as font-size, font-color, font-weight, and ...

I am experiencing issues with my Ajax code where it is not successfully sending data to the server and

Can someone help me troubleshoot my PHP AJAX code? I am new to PHP and just getting started with learning AJAX. index.html: <html> <head> <script> function sendmessage(str) { var xmlhttp; if (window.XMLHttpRe ...

What is the best way to choose all the options in a drop-down menu using Selenium Webdriver?

Currently, I am working with Selenium WebDriver and utilizing Java. In my application, there is a dropdown menu named Product containing multiple values (for example: 60). When running the code, I first deselect all options and then select the specific opt ...

Arranging Divs Inside a Container Div - Dealing with Overflow

I am in the process of developing a website that includes a unique structure that I have not encountered before. This layout involves joining multiple sections within a wrapper. As this is my first time attempting such a layout, I am encountering some chal ...

The Kenburn zoom image effect fails to function

I want to implement a zoom effect on an image using the Ken Burns effect when it is clicked. However, the code I have written does not seem to be working as expected. Here is the code snippet: $(document).ready(function () { $('.kenburns').on( ...

Collaboration of Bootstrap components

I am facing an issue with two divs that are supposed to be displayed side by side in a normal browser. However, when the browser window is resized, the first div loses its height and the second div overlaps into it. I attempted to set the body's min h ...

Scrolling text blocks on mobile devices

When viewing the website on a desktop, everything works perfectly. However, when accessing it on a mobile device and trying to scroll down, only the text moves while the page remains stationary. The website utilizes skrollr core for animations. I have alre ...

What crucial element am I overlooking in the React Transition Group Component while implementing it for a carousel design?

I'm trying to add a feature to my Carousel where the opacity changes between images. When clicking on the icons, the images should transition smoothly. I've been using React Transition Group, but for some reason, it's not working as expected ...

Why does Socket.IO seem to be registering two clients instead of just one when there is only one connection

When using my app, the user first lands on the home screen where they can select their username. They then proceed to another page and from there, navigate to the room entry page. The issue I'm facing is with a specific section of my code that update ...

Implementing a PHP form for seamless image uploads

I have been attempting to upload a form that includes an image. I have successfully retrieved the data for the brand name and other fields. However, I am encountering an issue with retrieving the image name and type. Can someone please assist me in ident ...

Scroll effortlessly with wrapping divs

Hey there! I've been experimenting with the Smooth Div Scroll plugin which you can find on their website here: The implementation is pretty simple. I'm using the touch example, but with a twist - instead of images, I am using Divs to scroll thro ...

Effortlessly Styling Children Elements in Emotion JS When Parent Element is Hovered

This particular query seems to have been posed and resolved in various ways, but the solutions I've come across either do not pertain to Emotion or the responses related to Emotion haven't yielded results for me. I am currently using @emtion/[ema ...

Ways to streamline repetitive CSS rules within media queries

As I work on defining multiple media queries, I realize there is some redundant code within them: @media only screen and (max-width:768px), only screen and (min-width:769px) and (max-width:1040px) { .list__figure { margin-right: 20px; ...