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

align radio button inline with text

I tried the following with flex but it looks like the radio button is slightly lower than it should be. probably to accommodate letters like j q g but not a b c. Is there a way to adjust?

.panswers {
  display: flex;
  align-items: center;
}
<div class='panswers'>
  <label for='ans[1]'>A</label>
  <input type='radio' name='ans[1]' id=a ns[1]>
  <p>Why are local variable names beginning with an underscore discouraged?</p>
</div>

>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

Radio buttons have a small margin on the top by default, which causes it to be misaligned in a flex container. Setting that margin to be zero fixes the issue

.panswers {
  display: flex;
  align-items: center;
}

input {
  margin-top: 0;
}
<div class='panswers'>
  <label for='ans[1]'>A</label>
  <input type='radio' name='ans[1]' id=a ns[1]>
  <p>Why are local variable names beginning with an underscore discouraged?</p>
</div>
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