Issues with Bootstrap container causing overflow and lack of responsiveness (resulting in consistent display of two columns)

I'm facing an issue with a form layout I created that has two columns. Even when the browser width is decreased and the content overflows, the two columns remain the same. I've attempted modifying the code by using plain DIV with the container class, specifying column count, setting width constraints but it's not working as expected.

You can view the codepen here: https://codesandbox.io/s/stoic-goldberg-4ugt6

Below is the source code of the parent container:

<div class="container flex-wrap pt-3 w-75 ml-auto mr-auto mt-auto mb-5">
  <div class="row">
    <div class="col">
      <b-card>
        <SeriesForm />
      </b-card>
    </div>
    <div class="col">
      <b-card :header="captions[1]">
        <SeriesForm :group="forms[1]" />
      </b-card>
    </div>
  </div>
  <div class="row">
    <div class="col text-center p-4">
      <b-button>Analyse</b-button>
    </div>
  </div>
</div>

I am looking for a solution to make it display as two columns when there is enough space available, and switch to a single column layout when needed.

https://i.sstatic.net/doGx7.png

Answer №1

To customize your layout, experiment with classes such as col-sm-6, col-xs-6, col-md-6, or col-lg-6 based on your requirements.

<div class="container flex-wrap pt-3 w-75 ml-auto mr-auto mt-auto mb-5">
  <div class="row">
    <div class="col-sm-6">
      <b-card>
        <SeriesForm />
      </b-card>
    </div>
    <div class="col-sm-6">
      <b-card :header="captions[1]">
        <SeriesForm :group="forms[1]" />
      </b-card>
    </div>
  </div>
  <div class="row">
    <div class="col text-center p-4">
      <b-button>Analyse</b-button>
    </div>
  </div>
</div>

Answer №2

The problem does not lie with the bootstrap grid itself; rather, it is related to how your checkboxes are being presented.

By specifying in the .align-nicely class that your checkbox group should always be 3 columns wide, you are limiting its flexibility. The display: grid property follows these instructions strictly, resulting in content overflow.

To address or enhance this issue, consider adjusting how the grid columns are managed using CSS.

One approach could involve utilizing CSS @media queries to determine the number of columns based on screen width, allowing for responsive scaling as the screen size changes.

The following CSS snippet should prove effective when used in conjunction with <b-col xl='6'> alongside your existing text:

.align-nicely {
  display: grid;
  grid-column-gap: 10px;
  grid-row-gap: 10px;
  grid-template-columns: 1fr 1fr 1fr;
}

@media screen and (max-width: 1350px) {
  .align-nicely {
    grid-template-columns: 1fr 1fr;
  }
}

@media screen and (max-width: 576px) {
  .align-nicely {
    grid-template-columns: 1fr;
  }
}

Alternatively, you can explore using the repeat() function in combination with minmax(). While this method offers greater dynamism than the previous one, it may impact alignment consistency across different groups.

.align-nicely {
  display: grid;
  grid-column-gap: 10px;
  grid-row-gap: 10px;
  /* 
    The 110px value inside minmax(), determines the minimum column size.
    If a column cannot fit within the available space on the current row,
    exceeding 110px, it will move to a new row. Adjust as needed based on content size.
  */
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
}

Answer №3

The issue arises due to the flex display,

To resolve this, ensure that the columns are set below your row for each form:

Replace <div class='col'> with

<div class='col-12 col-xl-6'>
. The spacing may be a bit tight, so consider adjusting margins and paddings accordingly.

By making this change, each form will occupy the entire width on larger screens and 50% width on extra-large screens.

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

How to create space between elements in CSS without using margin or padding?

Recently, I stumbled upon a fascinating website while working on my own CSS grid project: I am curious to know how it was achieved. The Portfolio elements on the website have space between them without any visible margins or paddings that I could identify ...

When using AngularJS ng-controller, the HTML href does not effectively call any div elements

As I was working with HTML and using AngularJS ng-controller, I encountered an error in the URL where a slash appeared. For example, localhost:8080/test/#/m1. Can someone please provide guidance on how to resolve this issue? <style> a{ } ...

Chrome does not support CSS animation rotation over 360 degrees

After researching for hours, I've encountered an issue with my animation in Chrome. It seems that while transform: rotate(1080deg); works flawlessly in Firefox, it fails to rotate in Chrome. Surprisingly, I discovered that it only rotates in Chrome wh ...

Guide for changing the background color exclusively in the final row of a dynamically-generated HTML table with PHP

<table width="100%"> <tr> <? $count=0; $i=1; foreach($gallery as $key => $list1) { $count++; ?> <td> <img src='<?echo base ...

Determining if an object is visible on the screen (with no reliance on scrollbars)

Is there a way to optimize rendering on a website by only displaying elements on the screen and rendering others when they are in view? Similar to 3D culling, but for a website ^.^ [update] Is it not feasible to achieve this effect? [update2] I experim ...

I am looking to dynamically assign CSS classes to elements in my HTML document. Additionally, my project utilizes Angular 5 and Bootstrap version 3.3.7

I am currently in the process of generating a table using data obtained from a JSON. Due to the potential for a large amount of data, I have implemented a loop to create all the rows within the table. My goal is to enable users to click on any specific row ...

Create a sleek transition for your Bootstrap 4 fixed Navbar by having it smoothly slide down and change to a

Throughout my experience with HTML/CSS, I have predominantly relied on themes that included this feature by default. However, as I now venture into building from scratch, I find myself struggling to recreate it. You'll notice that I have a stylish fi ...

The maskSize animation from Framer Motion is not functioning properly on mobile devices

I have successfully implemented a SVG mask scroll feature in Framer Motion. You can test it out on the sandbox by visiting this link: https://codesandbox.io/p/sandbox/svg-nextjs-masking-vgnhnd. However, there seems to be an issue with its performance on mo ...

The behavior of the jQuery slick slider is acting oddly

Currently, I have implemented the Slick Slider for my product loop in order to display the products in a slider format. However, upon the initial page load, there appears to be a significant white gap below the products. Interestingly, when I interact with ...

What is the best way to ensure that my header remains responsive across all devices and screen sizes?

The header is not responding despite inputting width: 100%. How can I ensure that the header is responsive on all browsers, as well as iPads and phones? .head-wrap { background: url(http://envisionmediallc.com/prodigy/wp-content/uploads/2014/02/We-are-p ...

Transforming hover interactions into onclick events involves adjusting the CSS and JavaScript

Is there a way to convert this hover menu into an onclick menu? <div id='cssmenu'> <ul> <li class='has-sub'><a href='#'><span>Users</span></a> <ul> ...

Leverage the input value from a text field within the same HTML document

Is it possible to utilize the input text value assigned to name='t0' within the same HTML document? Here's the code snippet you can refer to - <!DOCTYPE html> <head> <link rel="stylesheet" href="https://sta ...

What causes differences in the resulting width between buttons and inputs as opposed to divs and anchor tags?

Check out this JS Bin: http://jsbin.com/ojiJEKa/1/edit I have a question regarding the different width results of <div> and <a> compared to <input> and <button>, even though they have the same style applied. Can anyone explain why ...

Preventing a bootstrap data target from opening based on certain conditions

<button type="button" id="submitButton1" name="submitButton1" class="btn btn-primary waves-effect waves-light" ng-click = "validateAndSaveData('upload')" value="Upload Documents" data-target="#myModal1" data-t ...

Struggling to display bootstrap glyph icons on any browser

I am currently following a tutorial on .Net Core from Pluralsight that heavily relies on Bootstrap glyph icons. However, I'm facing an issue where none of the glyph icons are showing up in any browser on my Windows 10 system (I've tried both the ...

Disabled text selection in Internet Explorer

I am in need of making one HTML element (Label) unselectable for IE. I have tried using the following methods: Unselectable=on onselectreturn=false; Unfortunately, none of these solutions are working for me. For Firefox and Chrome, I've successful ...

How can I fully personalize the ion-toggle in Ionic?

When customizing <ion-toggle> within Ionic, I encounter an issue with toggle selection in CSS. Even though I have successfully customized two <ion-toggle> elements using CSS, I struggle to give them different customizations separately. In addi ...

Setting constraints for table size with min-width and max-height

I have a coding dilemma involving the min-width and max-height properties in my table. The issue arises when I try to set these properties on the td element – they are being ignored by the browser. If I nest a div with the properties inside a td, the con ...

What's the best way to enable touch scrolling for items within a div container?

I am in the process of creating a code snippet that will allow users to scroll through items within a div, similar to a spinning wheel or slot machine. While I am aware of an existing solution for iPhone and iPod, I want to develop a simpler, more streamli ...

Prevent border duplication in CSS and retain border visibility

Check out this fiddle where I have three divs with a border-width of 2px. Originally, the issue was that each div's border gets duplicated in between, resulting in a total border-width of 4px. To solve this, I applied a margin-top of -2px to each div, ...