How to Align Checkbox Buttons in a Bootstrap 4 Row

Trying to align checkboxes as buttons in Bootstrap is proving to be a challenge. The usual methods like "text-center" and "center-block" have been attempted within the surrounding divs and inputs but without success. (The unsuccessful attempts can be observed in the provided example where "text-center" and "center-block" are used frequently.)

HTML:

    <div class="row grade-selection">
      <div class="col-xs-1"></div>
      <div class="col-xs-2 btn-group text-center" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">K</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary text-center">
          <input type="checkbox" autocomplete="off">1</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input class="text-center" type="checkbox" autocomplete="off">2</label>
      </div>
      <div class="col-xs-2 btn-group center-block" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">3</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary center-block">
          <input type="checkbox" autocomplete="off">4</label>
      </div>
      <div class="col-xs-1"></div>
    </div>
    <div class="row grade-selection">
      <div class="col-xs-1"></div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input class="center-block" type="checkbox" autocomplete="off">5</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary active">
          <input type="checkbox" checked autocomplete="off">6</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary active">
          <input type="checkbox" checked autocomplete="off">7</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">8</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">9</label>
      </div>
      <div class="col-xs-1"></div>
    </div>
    <div class="row grade-selection">
      <div class="col-xs-3"></div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">10</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">11</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">12</label>
      </div>
      <div class="col-xs-3"></div>
    </div>

  </div>
</div>

To demonstrate the issue, I have created a Fiddle with one of the divs highlighted in a different color for clarity on the lack of alignment: https://jsfiddle.net/rovh1fcw/3/

Your assistance in resolving this matter is greatly appreciated! It seems to be a simple oversight on my part.

Answer №1

The text-center class has been replaced with text-xs-center in Bootstrap 4 alpha. It is also recommended to eliminate the btn-group from your columns to prevent the button from displaying inline.

<div class="col-xs-2 text-xs-center" data-toggle="buttons">
  <label class="btn btn-primary text-xs-center">
  <input type="checkbox" autocomplete="off">1</label>
</div>

DEMO:

Learn more about upgrading to Bootstrap 4

Answer №2

div[data-toggle]{  
   display: grid;
    grid-template-columns: auto;
    grid-template-rows: auto;
    justify-content: center;
    align-items: center;
}

https://jsfiddle.net/abc123xyz/25/

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

Admin template system for CodeIgniter

In order to give the Administrator the ability to customize the Admin Dashboard Layout and provide an option for them to upload their own layouts or "Premium" layouts, I need to implement a solution. I have considered one approach: Utilizing CSS (allowin ...

What is the process to showcase a database value in a particular index of an HTML table?

I am looking for assistance with displaying selected data values from a database into specific positions in an HTML table. I have managed to write the code that displays the data, but it only shows up at index 0 on the table. Does anyone know how to make ...

Different ways to modify the color and thickness of a variable in HTML5 with either JavaScript or CSS

I am currently working with a JavaScript file where I have a variable defined as follows: var nombre = document.getElementById('nombre').value; The 'nombre' variable corresponds to an element in an HTML file: Nombre: <input type=" ...

display a dual-column list using ngFor in Angular

I encountered a situation where I needed to display data from an object response in 2 columns. The catch is that the number of items in the data can vary, with odd and even numbers. To illustrate, let's assume I have 5 data items to display using 2 co ...

seamless blend of canvas distortion and gradual appearance of particles

Take a look at my work in progress on jsfiddle: https://jsfiddle.net/vzrandom/fkho6grf/8/ I'm experimenting with simplex-noise.js and dat.GUI to add movement to particles. Every 5 seconds, a simulated click occurs on the canvas triggering the start ...

The controls for the Bootstrap carousel component do not have a clear appearance

Trying to implement a Bootstrap carousel component but facing an issue with the controls not appearing transparent like in the example provided in the Bootstrap documentation. Check out the code snippet: <div class="carousel slide" id="s ...

What is the best way to place two radio buttons side by side in a row?

How can I place two radio buttons in a single row with their labels, like the example shown in the picture? ...

Alert: Unresolved Promise Rejection Notification in the world of Express.js and Node.js!

Recently delving into the world of Node.js and Express.js, I've been attempting to incorporate the Shippo API into my E-commerce website. Unfortunately, I have encountered persistent errors that have proved challenging to troubleshoot despite numerous ...

The Bootstrap navbar branding element vanishes upon navigating away from the home page

I have recently started learning Python, Django, and Bootstrap. I am facing an issue where the navbar-brand disappears when navigating to a different page or view other than the index. In my case, the nav-brand is an image source. Below is the code snippet ...

Tips for creating a CSS selector for a button

<div class="test" data-credit-card-index="1"> <button class="test1 test">Delete</button> <button class="test1 test">Edit</button> I'm trying to create a CSS locator specifically for the Edit button within the [d ...

Is there a way to modify the text within a hyperlink using jQuery?

Here is the link HTML code snippet: <a href="#" onclick="run(1); return false;" class="link" title="Remove item">[x]</a> I am looking to modify this using jQuery to display like this: <a href="#" onclick="run(1); return false;" class= ...

Modifying Row Color in Bootstrap 3: A Step-by-Step Guide

I'm trying to customize the background color of alternating rows in a Bootstrap 3 grid. I attempted to use CSS and add it to the class within the div, but unfortunately, the color isn't changing as expected. Below is the CSS code I used: .row-b ...

Navigate through AJAX Live search using arrow keys and mouse controls

I have encountered an issue with the autocomplete feature on my webpage. Although I am able to input suggestions, I am unable to navigate through them using the mouse pointer initially. Oddly enough, if I press the up/down keys once after the list items ar ...

Populate the table with JSON object information

I've structured a table as follows: <div class="row"> <div class="row"> <table class="table table-bordered table-striped tree-grid"> <thead class="text-primary"> <tr> <th> ...

placeholder for selecting a file

I'm struggling to replace "no file chosen" with "cv" on the file input field. I tried adding a placeholder, but it didn't work as expected. https://i.sstatic.net/wQqcS.png <div class="col-md-6 form-group "> ...

The Javascript function is designed to function exclusively with onclick events or setTimeout functions

I am currently working on a website that I want to be responsive to the window size. However, I am facing an issue with vertical alignment. I have created a jQuery function to handle this, and it works well for divs with images but not so well for a div wi ...

transfer information from a modifiable grid in a jsp file to a servlet

As a beginner in JSP's and servlets, I am tasked with allowing users to input questions into an HTML table and then passing that data to a servlet. The number of questions can vary, so I'm looking for a more efficient way to pass this data rather ...

The background on my modal remains unchanged

I have integrated a modal using Iframe for user login/registration on my website. Here is the HTML code: <div class="modal" id="ays-popin-connexion" aria-hidden="true"> <div class="modal-body" aria-hidden="true"> <iframe src=" ...

Ways to make the background color white in Bootstrap 5

Can someone assist me in changing the background color of my portfolio to white? I attempted to use global CSS, but the black background on both sides of the page is preventing the change. return ( <> <Navbar /> <main className= ...

Interactive button with jQuery that toggles between clicked and unclicked states, automatically reverting to unclicked when clicked elsewhere on the page

I am trying to create a button that changes its appearance when clicked, and returns to its normal state if clicked again or if the user clicks outside of it. Here is the JavaScript code I have written: if($('#taskbar-start').hasClass('ta ...