Centering text (vertically) inside a textbox using CSS

后端 未结 3 648
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 17:42

I\'m currently working with a textbox that has a background. I was wondering if it\'s possible to center text (vertically) inside the textbox.

important

相关标签:
3条回答
  • 2021-01-12 18:11

    Did you try?:

    input {vertical-align: middle;}
    
    0 讨论(0)
  • 2021-01-12 18:23

    I wonder how you are able to align the text in a textbox but since you say, here is the suggestion:

    For idiot IE, you can use this IE specific hack:

    margin-top:50px; /* for standard-compliant browsers */
    *margin-top:50px; /* for idiot IE */
    _margin-top:50px; /* for idiot IE */
    

    You might want to try other similar properties if you want rather than margin-top.

    0 讨论(0)
  • 2021-01-12 18:34

    I know this one's a bit old, but I've just run into the same problem. The solution given here didn't help me which seemed strange. In my case it was the line height that was set to "1em". Changing the line height to something that resembled the height of the text box, rather than the size of the font it contained was the solution. This also continues to function as expected in Firefox, etc.

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