The issue you're experiencing is that the checkbox is taking up too much space while the label text is getting squashed. This is happening because of the display: flex on the label element combined with the default checkbox sizing behavior.
Here are a few solutions to improve the readability while maintaining your structure:
Solution 1: Add flex properties to control sizing
.checkbox-group label {
display: flex;
align-items: flex-start;
gap: 10px;
cursor: pointer;
}
.checkbox-group label input[type="checkbox"] {
flex-shrink: 0; /* Prevents checkbox from shrinking */
margin-top: 3px; /* Aligns checkbox with first line of text */
}
/* Ensure the text takes up the remaining space */
.checkbox-group label {
flex-wrap: nowrap; /* Prevents wrapping to next line */
}
Solution 2: Use CSS Grid for better control
.checkbox-group label {
display: grid;
grid-template-columns: auto 1fr;
gap: 10px;
align-items: start;
cursor: pointer;
}
.checkbox-group label input[type="checkbox"] {
margin-top: 3px; /* Fine-tune vertical alignment */
}
Solution 3: Restructure HTML for better semantic markup
If you're open to slightly modifying your HTML structure, this approach provides better accessibility:
<div class="form-group checkbox-group">
<div class="checkbox-item">
<input type="checkbox" id="reg-is-mes-user">
<label for="reg-is-mes-user">Are you using an MES?</label>
</div>
</div>
<!-- For the multiple checkboxes -->
<div class="form-group">
<p class="group-label">If yes, which SAP products do you use? (check all that apply)</p>
<div class="checkbox-group">
<div class="checkbox-item">
<input type="checkbox" id="sap-mii-check" class="sap-product" value="MII">
<label for="sap-mii-check">MII</label>
</div>
<!-- Repeat for other checkboxes -->
</div>
</div>
With CSS:
.checkbox-item {
display: flex;
align-items: flex-start;
gap: 10px;
margin-bottom: 8px;
}
.checkbox-item input[type="checkbox"] {
flex-shrink: 0;
margin-top: 3px;
}
.checkbox-item label {
cursor: pointer;
line-height: 1.6;
}
.group-label {
margin-bottom: 10px;
font-weight: 500;
}
Quick fix for your current structure
If you want to keep your exact HTML structure, add this CSS:
.checkbox-group label {
display: flex;
align-items: flex-start;
gap: 10px;
}
.checkbox-group label input[type="checkbox"] {
flex: 0 0 auto; /* Don't grow or shrink */
width: auto; /* Reset any width constraints */
margin-top: 3px; /* Align with text baseline */
}
/* Ensure text doesn't overflow container */
.form-group {
word-wrap: break-word;
overflow-wrap: break-word;
}