How do I vertically align text in a paragraph?

前端 未结 9 1627
余生分开走
余生分开走 2020-12-05 04:12

I would like to know to align the text in a p element to be vertically centered.

Here are my styles:

相关标签:
9条回答
  • 2020-12-05 04:44

    In my case margin auto works fine.

    p {
        font: 22px/24px Ubuntu;
        margin:auto 0px;
    }
    
    0 讨论(0)
  • 2020-12-05 04:45

    If you use Bootstrap, try to assign margin-bottom 0 to the paragraph and after assign the property align-items-center to container, for example, like this:

    <div class="row align-items-center">
         <p class="col-sm-1 mb-0">
              ....
         </p>
    </div>
    

    Bootstrap by default assign a calculate margin bottom, so mb-0 disabled this.

    I hope it helps

    0 讨论(0)
  • 2020-12-05 04:49

    Alternative solution which scales for multi-line text:

    Set vertical and horizontal padding to be (height - line-height) / 2

    p.event_desc {
        font: bold 12px "Helvetica Neue", Helvetica, Arial, sans-serif;
        line-height: 14px;
        padding: 10.5px 0;
        margin: 0px;
    }
    
    0 讨论(0)
提交回复
热议问题