Vertical Align text in a Label

前端 未结 14 1638
攒了一身酷
攒了一身酷 2021-02-06 20:27

I have been asked to vertically align the text in the labels for the fields in a form but I don\'t understand why they are not moving. I have tried putting in-line styles using

相关标签:
14条回答
  • 2021-02-06 21:08

    I came across this trying to add labels o some vertical radio boxes. I had to do this:

    <%: Html.RadioButton("RadioGroup1", "Yes") %><label style="display:inline-block;padding-top:2px;">Yes</label><br />
    <%: Html.RadioButton("RadioGroup1", "No") %><label style="display:inline-block;padding-top:3px;">No</label><br />
    <%: Html.RadioButton("RadioGroup1", "Maybe") %><label style="display:inline-block;padding-top:4px;">Maybe</label><br />
    

    This gets them to display properly, where the label is centered on the radio button, though I had to increment the top padding with each line, as you can see. The code isn't pretty, but the result is.

    0 讨论(0)
  • 2021-02-06 21:13

    You can use flexbox in 2018+:

    .label-class {
        display: flex;
        align-items: center;
    }
    

    Browser support: https://caniuse.com/#search=flexbox

    0 讨论(0)
提交回复
热议问题