Vertical Align text in a Label

前端 未结 14 1639
攒了一身酷
攒了一身酷 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 20:59

    Adding disply:flex property to the label will get the job done!

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

    The vertical-align style is used in table cells, so that won't do anything for you here.

    To align the labels to the input boxes, you can use line-height:

    line-height: 25px;
    
    0 讨论(0)
  • 2021-02-06 21:03

    Use css on your label.

    For example:

    label {line-height:1em; margin:2px 5px 3px 5px; padding:2px 5px 3px 5px;}
    

    Notice that the line-height will adjust the height of the line itself, whereas margin will dictate how far out other elements will be outside the lable and padding will dictate any inner space from the outside edge of the label. The margin and padding work like this (clockwise: Top Right Bottom Left), so 2px 5px 3px 5px is:

    2px Top 5px Right 3px Bottom 5px Left

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

    You don't have to add any padding or edit the line-height!

    Instead, just make sure that when you have an HTML like this :

    <label><input type="checkbox" name=""><span>Checkbox Text</span></label>
    

    Just make sure that the input height and width are the same, and the the text has the same font size.

    Then, it will look perfectly fine and looks centered.

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

    None of these worked for me. I am using ASP.Net MVC with Bootstrap. I used the following successfully:

    .label-middle { 
        padding-top:6px;
    }
    
    <label id="lblX" class="label-middle" ></label>
    

    This vertically aligned the label with the textbox next to it.

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

    Have you tried line-height? It won't solve your problems if there are multiple row labels, but it can be a quick solution.

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