Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I get These Rows of checkboxes to line up?

I am trying to make a checklist out of checkboxes in a grid-like format, but am having trouble getting the top row of checkboxes, which are the only ones with labels, to line up with the rest. It looks like the checkboxes up top are spaced apart based on their label length, so I think I just need to find the portion of the code that causes that and remove it, but I cannot seem to find it. Can someone help me? The code is down below.

    <head>
<style>
.checkboxes input{
  margin: 10px 20px 10px 20px;
}
ul{
      display: flex;
      align-items: flex-start;
      justify-content: center;
      margin:0px; padding:0px;
    }
    ul li{
      display: flex;
      align-items: center;
      justify-content: center;
      flex-wrap:wrap;
    }
    ul li label{ text-align:center; display:block; width:100%;}

</style>

<center>
</head>

<body>
<br><br><br>
<ul>
  <li>
  <label>Inspect</label><input type="checkbox">
  </li>
  <li>
 <label>Repair</label><input type="checkbox">
  </li>
  <li>
  <label>New Part</label><input type="checkbox">
  </li>
  <li>
  <label>Unit Exch</label><input type="checkbox">
  </li>
  
  </ul>

<div class="checkboxes">


<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<br>

<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<br>

</body>

    

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try this, not using flexbox to get consistent behaviour,

ul {
  list-style: none;
  margin: 0;
  padding: 0;
  padding-top: 18.5px; /* Height of Lable */
}

ul li {
  display: inline;
  position: relative;
}

ul li label {  
  position: absolute;
  transform: translateY(-100%);
  white-space: nowrap;
}

ul li input,
.checkboxes input {
  margin: 10px 20px 10px 20px;
}
<ul>
  <li>
    <label>Inspect</label><input type="checkbox">
  </li>
  <li>
    <label>Repair</label><input type="checkbox">
  </li>
  <li>
    <label>New Part</label><input type="checkbox">
  </li>
  <li>
    <label>Unit Exch</label><input type="checkbox">
  </li>

</ul>

<div class="checkboxes">


  <input type="checkbox">
  <input type="checkbox">
  <input type="checkbox">
  <input type="checkbox">
  <br>

  <input type="checkbox">
  <input type="checkbox">
  <input type="checkbox">
  <input type="checkbox">
  <br>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading