What is the best way to stack col-xs-6 elements instead of having them side by side?

My form fields are currently set up using 3 col-xs-6 classes, but I'm not seeing the desired layout.

I am aiming for:

| col-xs-6 | 
| col-xs-6 |
| col-xs-6 |

However, what I am getting is:

| col-xs-6 | col-xs-6 |
| col-xs-6 |

I understand that this is the default behavior, but I really want to achieve the initial layout. I tried adding a row class to each col-xs-6 but it didn't work.

This is my HTML structure:

<div class="col-xs-12">
   <h1>Form</h1>

   <form class="top20" ng-submit="vm.exportForm()" name="vm.exportForm" novalidate>
       <formly-form model="vm.exportModel" fields="vm.exportFields" form="vm.exportForm"></formly-form>
   </form>
</div>

And here is how I defined the form in the controller:

vm.exportFields = [
    {
        className: 'col-xs-6',
        key: 'field1',
        type: 'select2',
        templateOptions: {
            label: 'Field1',
            valueProp: 'subCode',
            labelProp: 'description',
            options: []
        }
    },
    {
        className: 'col-xs-6',
        key: 'field2',
        type: 'select2',
        templateOptions: {
            label: 'Field2',
            valueProp: 'subCode',
            labelProp: 'description',
            options: []
        }
    },
    {
        className: 'col-xs-6',
        key: 'field3',
        type: 'select2',
        templateOptions: {
            label: 'Field3',
            valueProp: 'subCode',
            labelProp: 'description',
            options: []
        }
    }
];

Update:

I have made a decision to switch my field classes to col-xs-12 and wrap them within a <div class="col-xs-6"></div>. This setup has given me the expected outcome. Thank you, everyone!

Answer №1

To display them on separate lines, enclose them within a .row:

.row
  | col-xs-6 |
.row
  | col-xs-6 |
.row
  | col-xs-6 |

For more advanced layouts, experiment with using classes like .push and .pull, along with .col-offset.

Answer №2

Instead of using col-xs-6, you should opt for col-xs-12 (which offers 100% width). Your issue arises from having three columns each with a 50% width, causing two to be adjacent while the third is positioned below the first pair.

Answer №3

Here is a suggestion for your code improvement.

vm.exportFields = [
    {
        className: 'col-xs-6 col-xs-offset-3',
        key: 'field1',
        type: 'select2',
        templateOptions: {
            label: 'Field1',
            valueProp: 'subCode',
            labelProp: 'description',
            options: []
        }
    },
    {
        className: 'col-xs-6 col-xs-offset-3',
        key: 'field2',
        type: 'select2',
        templateOptions: {
            label: 'Field2',
            valueProp: 'subCode',
            labelProp: 'description',
            options: []
        }
    },
    {
        className: 'col-xs-6 col-xs-offset-3',
        key: 'field3',
        type: 'select2',
        templateOptions: {
            label: 'Field3',
            valueProp: 'subCode',
            labelProp: 'description',
            options: []
        }
    }
];

Answer №4

All instances of col-xs-6 should be enclosed within the row class for proper formatting.

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">

<div class="container">

 <!-- Start of row  -->
  <div class="row">
    <div class="col-xs-6">
      My Text
    </div>
   </div>
  <!-- End of row  -->
  
  <!-- Start of row  -->
   <div class="row">
    <div class="col-xs-6">
      My Text
    </div>
   </div>
   
   <!-- Start of row  -->
   <div class="row">
    <div class="col-xs-6">
      My Text
    </div>
   </div>
   <!-- End of row  -->
   
 </div>

Answer №5

<div class="container-fluid">
  <div class="row">
    <div class="col-xs-6 " style="background-color:skyblue;">col-xs-6</div>
    </div>
     <div class="row">
    <div class="col-xs-6 " style="background-`color:lightcoral`;">col-xs-6</div>
    </div>
     <div class="row">
    <div class="col-xs-6 " style="background-color:skyblue;">col-xs-6</div>
    </div>
  </div>
</div>

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

"Firebase offers the flexibility to have several 'apps' configured, both on the client side and the server

Currently, I have a firebase app set up in my project for SSR using firebase-admin. However, I now want to add firebase@8 to be able to utilize it on the client-side and eventually apply firestore rules. The issue arises when I try to use firebase@8, I enc ...

Troubleshooting a dysfunctional Vue.js component

I am currently facing a challenge in getting components to function properly. Interestingly, without the component, everything seems to be working fine (as per the commented code). Here is my HTML snippet: <strong>Total Price:</strong> <sp ...

Creating an If statement tailored for a particular image source: a step-by-step guide

In the program I am running in Dreamweaver, there is a specific line of code that looks like this: function go() { if((document.test.test1.src == document.test.test2.src && document.test.test2.src == document.test.test3.src )) ...... ...... ..... ...

Creating nested subitems in AngularJS ng-optionsWant to create a dropdown list in Angular

How can I populate an Angular ng-options with values from the JSON returned logins data? The problem lies in accessing attributes like login, id, url, etc., which are nested subitems. The HTML <html ng-app="myapp"> <head> ... </head> &l ...

Maintaining a consistent style input until it is modified

I'm currently dealing with this code (continuing from a previous question): input[type=submit]:focus { background-color: yellow; outline: none; } The issue I'm facing is that when I click anywhere else on the screen, the background color go ...

Stop the submission of MVC Form

Using AJAX, I have a form with fields in a partial view that is sent to a controller action when submitted. The partial view appears in a pop-up div when a button on the main form is clicked. If the user completes and submits the form, the update is succes ...

The functionality of app.get('') is malfunctioning in Node.js when it comes to handling query parameters

I'm currently working on updating my conversation application to handle new routes that accept parameters and pass them along to the client side. However, I'm facing an issue with the .get() method not rendering the HTML as expected. 'use s ...

Utilizing jQuery to access data stored locally

How can I retrieve and display all the values with key 'Task'? Below is the structure of the JSON data: {"Assignments":[{"AssignedBy":"537000","AssignedBy_FirstName":" JOHN","AssignedBy_LastName":"WANDER"}, {"AssignedBy":"537000","AssignedBy_Fir ...

Is there a way for me to adjust the image dimensions so that it doesn't surpass the width of its parent container?

When working with images, it can be tricky to set the original width while also ensuring it fits within a parent container. For example, if the parent container has a width of 1000px, you may want the image to have a max-width of 100%, but not exceed 1000p ...

Can data be transferred between browsers, such as from Google Chrome to Mozilla Firefox?

I have a dilemma with two separate pages—one for Admin and the other for User. The Admin page is named index.html <!DOCTYPE html> <html lang="en"> <head> <style> * { padding: 0; ...

Issue with integrating Razorpay into a Node.js Express application

I am currently working on setting up a checkout page using nodejs and express with Razorpay as the payment gateway. The issue arises when trying to run the checkout() function by clicking the "Checkout" button within my shopping-cart.hbs file. Despite havi ...

Bootstrap CSS: image is overlapping text inside a div

In my layout, I have four inner div containers arranged as follows: small picture - text - small picture - text. <div class="container"> <div class="col-md-12"> <div class="row"> <div class="col-sm-2"> <div c ...

Getting state values from a custom component to another parent component can be achieved by lifting the state up

In my project, I have two classes both extending React.Component. One of these classes is a custom component that is built upon another custom component called React Places Autocomplete. If you want to see how it looks, check out this picture. Here is the ...

The scope chain in Chrome v71 connects the anchor tag to the inner img tag

Ever since updating to Chrome v71, I've noticed a strange issue with the scope of an anchor tag that contains an img tag inside. Take a look at this snippet: <a href="#none" onclick="debugger;complete();"> <img src="https://clickmeuk.net/w ...

Nodemon is failing to automatically re-run the changes I've made in my local codebase

Recently, I developed a basic node function that simply outputs "hello world." When I ran the script using the command line node myfirst.js, it successfully displayed the message in the browser. Then, I decided to install nodemon so that it would re-exec ...

Can anyone tell me where to locate the AndroidManifest.xml file within a React Native Expo project?

How can I locate the AndroidManifest.xml file in a React Native Expo project to request permissions? Are there alternative methods for asking users for permission? ...

Navigating the issue of "Experiencing additional hooks rendered compared to the previous render"

I'm currently in the process of developing a small application where certain elements will be nested within one another. My approach involves segmenting each component into its own file (children), returning a function with two components in each Rend ...

What is the best way to implement a CSS transition for styles that are dynamically created by React?

I have a situation where I am using a button component that is styled based on a theme provided by a context: The code in Button.js looks like: () => { const theme = useContext(themeContext); // { primaryColor: "blue" } return <button className ...

Using async/await in a POST handler within Express.js

My goal is to invoke an async function within a POST handler. The async function I'm trying to call looks like this (the code is functional): const seaport = require("./seaport.js"); // This function creates a fixed price sell order (FPSO) ...

Is it necessary to include the Fonts file (which accompanies Bootstrap files) in the HTML document?

As a beginner in HTML, I decided to incorporate Bootstrap into my project. After downloading the necessary files, including css, js, and fonts, I found myself able to easily add the css and js files using the appropriate tags. However, I encountered some c ...