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

Display one div and conceal all others

Currently, I am implementing a toggle effect using fadeIn and fadeOut methods upon clicking a button. The JavaScript function I have created for this purpose is as follows: function showHide(divId){ if (document.getElementById(divID).style.display == ...

Performing code execution in MVC 5 View every 1 second

I am currently working on a MVC 5 web application and I have a question regarding performing real-time calculations in the view. Below is an example of my view code: var timeRemaining = Model.account.subscriptionEndDate - DateTime.UtcNow; Is there a way ...

Dynamic styling updates on page refresh in Next.js

There is a strange issue with my styling that I can't seem to figure out. I have a NavBar set to be 20vh in height and an image set to be 100% in width. However, whenever I refresh the page, the NavBar height decreases and the image width increases si ...

Words are cut off in a random manner on the entry content list for phone users

I struggle with CSS and have a basic understanding to make adjustments to my website. The issue I am encountering involves the .entry-content ul li elements. On desktop, they display correctly without random word breaks, but on mobile, words are being cut ...

CSS - Mysterious Gaps Found in Div Block

Below is the code snippet I am currently working with: html { height: 100%; overflow: hidden; } body { height: 100%; color: #bdc3c7; font-family: Montserrat; background-color: #3E4651; } .nav { ...

Alerting JavaScript with element Selector doesn't function at full capacity

I am currently implementing Notify JS from the following source : Below is the HTML code I am using: <div> <p><span class="elem-demo">aaaa</span></p> <script> $(".elem-demo").notify( "Hello Box" ...

What is the process for showcasing specific data using Vue.js?

{ "status": "ok", "source": "n", "sortBy": "top", "articles": [ { "author": "Bradford ", "title": "friends.", "url": "http: //", "urlToImage": "http://" }, { ...

How can I create a new PHP table using data from an existing table?

I have a table displayed on my website with the code snippet providedview the table image here Here is the code for generating this table: <?php $query = $db->query("SELECT * FROM bit_exchanges ORDER BY id DESC LIMIT 20"); if($query-> ...

How can I automatically scroll to an anchor element once CSS animation has finished

I am currently working on a CSS animation that looks like this: @-webkit-keyframes flip { 0% {opacity:1;} 100% {opacity: 0;} //This could be 90% //And here could be frame for 100% which would scroll it down. } #headercover { -webkit-animation-name ...

Delete the right-hand p-timeline-event-opposite margin from the Angular 17 PrimeNG Timeline

I am currently utilizing the PrimeNG Timeline module to showcase a few straightforward horizontal timelines with content placed on the top side in a table format. How can I eliminate the space allocated by the .p-timeline-event-opposite section? Upon inspe ...

Animate a Bootstrap icon displaying an unattractive border

When I click on a static Bootstrap glyphicon, I want to replace it with an animated one. My challenge is that if I use the replaceWith() function to completely swap out the icon, it looks great. However, if I try to just switch the classes using removeClas ...

Styling a list using multiple columns with CSS

My goal is to design a columned list using only HTML and CSS. I have experimented with floats and inline-block, but it seems like inline-block is the best option for me due to these specific requirements: The layout must be in columns; The number of colu ...

Adjusting and arranging multiple thumbnail images within a container of specific width and height

I need a user-friendly method to achieve the following. The thumbnails will not be cropped, but their container will maintain a consistent height and width. The goal is for larger images to scale down responsively within the container, while smaller image ...

A surprise awaits in IE with the unusual appearance of a div display

body { background: #9cdcf9 url(/images/left_cloud.png) bottom left no-repeat; font-family:\"Trebuchet MS\"; padding:0; margin:0; border:0; } #cloud-container { width: 100%; background: url(/images/right_cloud.png) bott ...

Instructions for implementing personalized horizontal and vertical scrolling within Angular 9

I am currently working on an angular application where users can upload files, and I display the contents of the file on the user interface. These files may be quite long, so I would need vertical scrolling to navigate through them easily. Additionally, fo ...

Is there a way to create a blurred background effect while the popup is in use?

I prefer my popup to have a dark or blurred background when active. The popup itself should remain the same, with only the background being darkened. I would like a dark layer overlaying the entire page. This script should be compatible with any website wh ...

What is the process for initializing the default/prefilled value of an input element within a mat-form-field when the page loads?

I'm looking to create an HTML element where the default data (stored in the variable 'preselectedValue') is automatically filled into the input field when the component loads. The user should then be able to directly edit this search string. ...

Manipulating classes within ng-class in AngularChanging classes in ng-class dynamically

Featuring multiple elements with an ng-class that behaves similarly to a ternary operator: ng-class="$ctrl.something ? 'fa-minus' : 'fa-plus'" To access these elements, we can compile all the ones with fa-minus and store them in a lis ...

Shift the column upwards for devices with smaller screens

I need help with a layout issue I am facing. Currently, my layout looks like this: [blurb] (8) [form] (4) However, I want the [blurb] to take up col-md-8 and the [form] to take up col-md-4 so that they are full width on smaller devices. On smaller devic ...

What are the steps for integrating a date and time picker bootstrap plugin?

Referencing a tutorial from http://www.w3schools.com/bootstrap/bootstrap_modal.asp: <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> <div id="myModal" class="modal fade" role= ...