Guidelines for organizing multiple checkboxes in a grid format

Hey there, I'm looking to create a 3x3 grid of checkboxes in a pop-up window. I found a similar example here: https://codepen.io/webdevjones/pen/qBapvrz. I tried using display: flex, but I'm unable to get the checkboxes in a grid format and the labels are not aligned properly.

Below are the HTML and CSS files:

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
/* CSS code goes here */

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <!-- Meta information -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <link href='https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed8f8295848e82839eaddfc3dcc3d9">[email protected]</a>/css/boxicons.min.css' rel='stylesheet'>
    <title>Sail Vision</title>
  </head>
  <body>
      <div class="modal-container-data">
        <div class="overlay">
          <div class="data">
            <div class="popup-header">
              <button class="close-modal modal-trigger-data">X</button>
              <h1>Data Selection</h1>              
            </div>
            <div class="popup-body">
              <div class="container-box">
                <input type="checkbox" id="entry" name="Entry">
                <label for="entry">Entry</label>
                <input type="checkbox" id="camber forward" name="camber forward">
                <label for="camber forward">Camber forward</label>
                <input type="checkbox" id="camber" name="camber">
                <label for="camber">Camber</label>
                <input type="checkbox" id="draft" name="draft">
                <label for="draft">Draft</label>
                <input type="checkbox" id="camber after" name="camber after">
                <label for="camber after">Camber after</label>
                <input type="checkbox" id="exit" name="exit">
                <label for="exit">Exit</label>
                <input type="checkbox" id="twist" name="twist">
                <label for="twist">Twist</label>
                <input type="checkbox" id="lateral sag" name="lateral sag">
                <label for="lateral sag">Lateral sag</label>
                <input type="checkbox" id="longitudinal sag" name="longitudinal sag">
                <label for="longitudinal sag">Longitudinal sag</label>
              </div>
            </div>
          </div>
        </div>
      </div>
  </body>
</html>

Thanks for your help!

Answer №1

To implement a CSS Grid, ensure that the grid container element only contains one child per checkbox. This can be achieved by wrapping the input in the label as shown here.

* {
  box-sizing: border-box;
}

body {
  font-family: sans-serif;
  background: #E4E9F7;
}

.data {
  margin: auto;
  background-color: #eee;
  padding: 0;
  width: 500px;
}

.container-box {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1em;
  padding: 1em;
}

.container-box label {
  white-space: nowrap;
}
    <div class="data">
      <div class="popup-body">
        <div class="container-box">
          <label for="entry"><input type="checkbox" id="entry" name="Entry">
                Entry</label>
          <label for="camber forward"><input type="checkbox" id="camber forward" name="camber forward">
                Camber forward</label>
          <label for="camber"><input type="checkbox" id="camber" name="camber">
                Camber</label>
          <label for="draft"><input type="checkbox" id="draft" name="draft">
                Draft</label>
          <label for="camber after"><input type="checkbox" id="camber after" name="camber after">
                Camber after</label>
          <label for="exit"><input type="checkbox" id="exit" name="exit">
                Exit</label>
          <label for="twist"><input type="checkbox" id="twist" name="twist">
                Twist</label>
          <label for="lateral sag"><input type="checkbox" id="lateral sag" name="lateral sag">
                Lateral sag</label>
          <label for="longitudinal sag"><input type="checkbox" id="longitudinal sag" name="longitudinal sag">
                Longitudinal sag</label>
        </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

Mobile site experiencing slow scrolling speed

The scrolling speed on the mobile version of my website, robertcable.me, seems to be sluggish. Despite conducting thorough research, I have not been able to find a solution. I have attempted to address the issue by removing background-size: cover from my ...

Adjust the width of Google chart to 100% automatically when the page is resized in Angular version 4 or higher

My application has numerous responsive wrappers on the site, each predefined from an API and containing a Google chart. The problem is that when the page initially loads, the charts are rendered at a specific size, and resizing the window only affects the ...

Is there a way to automatically adjust the position of a tooltip div based on its location relative to the screen in AngularJS?

I've implemented AngularJs to create a grid with repeated li elements, each displaying a description box when hovered over. However, I am facing an issue where the description box goes off-screen when hovering over items on the right side of the grid. ...

How to override an event in JavaScript when a specific value is entered

I am looking to implement a system with complex conditions. The goal is to have an alert appear when a value is inputted and the button is clicked. First, a confirmation message Have you input ? should be displayed, followed by clicked with input. If no va ...

Guide to incorporating animated material icons in vuetify

in Vuetify makes it easy to utilize mainstream material design icons through the use of the v-icon component. An example of this would be: <v-icon>home</v-icon> I am curious if animated material icons are supported and can be integrated in ...

The CSS code seems to be refusing to connect and cooperate with the Spring Boot application

https://i.sstatic.net/CUrYN.png This is an image of my current project. I have placed my css file in the static/css folder and I am attempting to connect it to my index.jsp page, but unfortunately, it is not functioning as expected. I have already tried ...

Fill the second dropdown menu options based on the selection made in the first dropdown menu

I need assistance with dynamically populating my second drop-down menu based on the selection made in the first drop-down. Here are the steps I've taken so far: form.php - Utilizing javascript, I have set up a function to call getgeneral.php. The se ...

Coding in PHP, JavaScript, and HTML allows builders

I am facing some difficulties in locating my specific question, so I will describe it here. Currently, I am working with an oracle database and integrating it into an HTML website using javascript and php. I have successfully displayed the php file, but th ...

Preventing scrolling in jQuery UI Draggable when using flexbox

In my project, I am looking to organize a container using jQuery UI draggable/droppable feature. Since the elements in my list are arranged in a straight horizontal line, I have utilized display: flex. This arrangement works well when adding new items to ...

Learn how to customize the global style within a child component in Angular and restrict the changes to only affect that specific component

I have applied some custom css styling in my global style.css file (src/style.css) for my Angular project. However, I encountered a problem when trying to override this styling in a specific component without affecting the rest of the project. Currently, I ...

Sliding Toggle: Panel Revealed with Button Slide

Currently, I am working on implementing a jquery slide tab feature. The functionality is working fine on button click. However, I want the button to stick with the panel and slide along with it. At the moment, the button remains fixed while the panel slide ...

What is the best way to create a transparent effect over a solid color using CSS in the following situation?

I have been using the spinner on this website "". Specifically, I am referring to the third one in the first row. When I apply it to my system, a solid color appears in the center of the circle. However, I want to make it transparent, but when I attempt ...

Send form data without reloading the page and connect it to a JavaScript script

I've designed a system that reveals values based on a specific input selection. Below is the main form where users can enter model numbers and press enter: <form> <input type="text" name="ModNum" id="ModelNumber" pattern="^PIV13RT[23]?$" ...

Tips on showcasing an array as a matrix with a neat line property

I am currently developing an application using TypeScript, and utilizing a JSON array structured like this: data = [{"name":"dog", "line":1}, {"name":"cet", "line":1}, ...

Is there a way to leverage the extensive Bootstrap 5 color palette within an Angular application?

Currently working on a project in Angular 12 with Bootstrap 5 and SCSS, I'm facing a challenge in utilizing the new extended Bootstrap 5 color palette such as indigo-300 or pink-200. I'm not sure if I need to import them in a certain way or how t ...

AngularJS dropdown not reflecting changes when using ng-selected

While working with AngularJS, I have encountered an issue where the first child of the select element remains empty despite my efforts to populate it. Below is the HTML code snippet: <select id="connectTV" aria-label="How many Dish TVs" ng-model="conn ...

javascript code for subtracting values in arrays

I am facing a scenario where I have 3 arrays of the same length. My requirement is to automatically subtract the values in the first two arrays without any user input. If the result of subtraction is negative, I need to identify the index of that array num ...

Forward the value of the selected radio button

Currently, I am focusing on this code snippet. <html> <script> var submit = document.getElementById('btnFormSubmit'); submit.addEventListener('click', submitForm); function submitForm(event){ event.preventDefault(); event. ...

Active tab in HTML

In my implementation based on this example code from https://www.w3schools.com/howto/howto_js_tabs.asp, I have a specific requirement. I want the tab for "Paris" to remain active even after the page is refreshed if the user has clicked on the button for "P ...

Challenges with Bootstrap input groups

Despite trying various solutions, nothing seems to be working for me. I attempted using width:200px, but the issue persists. Since my form was quite outdated, I decided to switch to a bootstrap version. However, while others are able to resolve the issue w ...