Make sure the bootstrap div rows are aligned side by side consistently, even when resizing the window

Is there a way to ensure that my buttons inside divs stay on the same line, even when the window is resized to be smaller? I set the table width to 20% as an example, but the buttons are still on separate lines. Should I add a min-width to the table so the row stays within it?

Desired layout:

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

Current layout:

<link
  href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
  rel="stylesheet"
/>
<table style="width:20%;">
  <tr>
    <td id="123">
      <div class='row ml-1'>
        <div class='col-xs-6 mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
      </div>
    </td>
  </tr>
</table>

Answer №1

Why complicate things by using row and col classes, when you can simply utilize flex on the div for the same layout?

<link
  href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
  rel="stylesheet"
/>
<table style="width:20%; ">
  <tr>
    <td id="123">
      <div class='ml-1 d-flex'>
        <div class='mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
      </div>
    </td>
  </tr>
</table>

Answer №2

First, I removed the width:20%; from your table and applied the .container class to your tr. Additionally, I included a .col-sm-auto class to ensure proper column layout.

It is advisable not to use margin (right/left) with columns but rather opt for padding to avoid any potential break points...

<link
  href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
  rel="stylesheet"
/>
<table style="">
  <tr>
    <td class="container" id="123">
      <div class='row ml-1'>
        <div class='col-xs-6 col-sm-auto mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 col-sm-auto mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 col-sm-auto mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 col-sm-auto mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
        <div class='col-xs-6 col-sm-auto mr-1 mb-3'>
          <button onclick='toggleHideShowTC(this.id)' id='33' title='Passed' class='btn btn-success rounded text-light font-weight-bold h6 p-1 d-inline-block'>
              2331 &#10003;
          </button>
        </div>
      </div>
    </td>
  </tr>
</table>

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

Creating a display of divs that flow from left to right in each row, and then stacking the rows from bottom to top using CSS and jQuery

My current dilemma involves a collection of divs that must be displayed in a specific order, but with a rather intricate layout. Essentially, this is the structure of my HTML: <div> <div class="box">1 (first in list)</div> <di ...

The Selenium element appears to have become unlinked from the page document

I am currently attempting to scrape data from a specific website using Python: . The information I need includes all the ISIN codes and company names. My approach involves extracting this data into two separate lists by targeting an entire column in the w ...

Maintain line breaks in the scanner input within an HTML element

Currently, I am utilizing a Zebra DS9908 scanner to scan a barcode and transfer the data onto an HTML page. However, I am encountering an issue with preserving all input characters. Despite attempting both a <div> and <textarea>, the line feed ...

What is the process for displaying a three.js project?

I've been trying to follow a beginner's tutorial on three.js from this link, but I'm encountering an issue in part 2 where nothing seems to render on my webpage. Despite checking out other guides, I can't seem to solve the problem. I u ...

Encountered error: "Node.js and socket.io: Address already in use"

Experimenting with chat using Node.js and socket.io Currently, I am running Ubuntu 12.04 as a user and have a folder "pp" on my desktop. In this folder, I have placed a server file named server.js. Below is the client code: $(document).ready(function() ...

Ways to control image width without distorting the image dimensions

Can anyone help me with writing an img tag for images of varying sizes? I'm looking to scale down larger images to fit the container at width: 100%, but I do not want smaller images to be scaled up. I want them to maintain their natural size when view ...

Discover the secret to toggling Bootstrap 4 cards visibility when hovering over the navigation menu using CSS

Hey, I'm currently working on a project where I want to show and hide specific sections of cards by just hovering over the menu list. While I can successfully hide the cards using CSS, I am facing issues with displaying them using the display:block pr ...

Using a series of functions that make use of (theID)

Hey there, I'm new to HTML and I've been trying to achieve something below. Unfortunately, it's crashing and I can't figure out if it's just a syntax error or if what I'm attempting isn't possible. The function declarati ...

Avoiding the collision of two absolutely positioned elements

I have a website mockup where I've placed two elements - a logo and a form on the screen. Both are positioned absolutely, but on smaller screens, they end up overlapping (or coming very close to it). Since you can't add margin-top to elements wit ...

Issues arise when setting a delay for CSS transitions to occur due to the

I'm trying to create a scroll bar that only appears when hovered over, similar to how it works on Facebook where the scroll bar shows up slowly instead of all at once. I've tried using CSS transition delay, but it doesn't seem to be working ...

Ways to adjust the position of a DIV based on its index value

I'm currently working on a unique project that involves creating a triangular grid using HTML and CSS. The challenge I am facing is offsetting each triangle in the grid to the left by increasing amounts so they fit seamlessly next to one another. Righ ...

Avoid placing dropdown items within the navbar container in Bootstrap 4

When collapsing the screen, I encountered an issue with the dropdown items being inside the navbar. I positioned the dropdown menu as absolute, but some items were getting cut off, and I didn't want the scroll bar to appear. Despite trying to use medi ...

What is the method for producing a vertical line of numerical dots utilizing CSS?

I am looking to add thick dots at specific locations along the vertical line between [div class="col-md-4"] and [div class="col-md-8"]. Here is what I have attempted: <div class="col-md-4" style="border-right:1px solid #333;"> <h1>1987</h1 ...

Unusual functionality when utilizing angular-ui-bootstrap date in an angular-ui-modal

I'm currently working on my debut Angular app and I've hit a roadblock. While using ui-bootstrap date picker in various sections, everything worked fine. However, when I tried integrating it into a modal, an issue arose. After selecting a date c ...

"Revamp Your Layout with Bootstrap 4's Customized Sorting Feature

I'm exploring methods to rearrange items on mobile using the md and col- classes to achieve the following layout: On Desktop: [1] [4] [2] [5] [3] [6] [7] For Mobile: [1] [2] [3] [4] [5] [6] [7] Is there a way to accomplish this without reso ...

What is the best way to adjust the size of the circles in my d3 leaflet implementation based on the frequency of longitude/latitude pairs?

I'm currently diving into the world of d3 and attempting to create a map using leaflet. Within my dataset, I have thousands of latitude and longitude coordinates. While I've successfully plotted circles on a leaflet map in d3, I'm now faced ...

When utilizing JavaScript within an Electron application file that is linked with a script tag in an HTML document, there may be limitations on using node modules with

While working on my Electron application, I encountered an issue with referencing a node module using require within an HTML form that includes JavaScript. Specifically, I am having trouble integrating the 'knex' node module into my code. Here i ...

Need assistance with CSS right now

I seem to be having trouble getting this to work correctly. I have a few menu items that require different background styles than the global settings. Here is the working global setting... #left #current a {background-image: url(../images/leftbuttonactiv ...

Retrieve the computed style of a cloned element that has not yet been appended to the document

I am dealing with an HTML page that looks like this: <div id="cloneDiv"> <h1> <a href="">ASUS Vivotab Smart Black Office 2013 H&S ME400C-C2-BK 10.1-Inch 64GB Tablet (Black)</a> </h1> <di ...

Assistance for Datepicker in Internet Explorer 11 and Mozilla Firefox

Why is the date picker not appearing in FireFox 30.0 and IE 11 on this simple HTML page? <!DOCTYPE html> <html> <head> <title>Untitled Page</title> </head> <body> <form> ...