How do I align text to the middle of an element with CSS in Twitter Bootstrap?

后端 未结 3 887
情书的邮戳
情书的邮戳 2021-02-06 01:41

I am using Bootstrap alerts and this is my success alert message:


      
3条回答
  •  心在旅途
    2021-02-06 02:02

    Trying to vertically center text text is a common issue. Normally this wouldn't work on normal boxes, but you can force it to work with vertical align:

    vertical-align: middle;
    display: table-cell;
    

    However this will not work in IE7 and lower.

    If you are sure the text you want to display you could use line-height to fake the effect like this:

    height: 40px;
    line-height: 40px; /* same as height */
    

    This way works cross browser and has support up to IE5.5 I believe. If this is not an option I'm afraid you're out of luck (it can't be done).

    As a side note that error message suffers from bad grammar, it should be "Congratulations! You have successfully done it.".

提交回复
热议问题