Bootstrap how to get text to vertical align in a div container

前端 未结 3 1103
Happy的楠姐
Happy的楠姐 2020-12-29 05:03

What is the best/proper way to vertically align the text in the middle of its column? The image height is statically set in the CSS.

I have tried setting an outer di

3条回答
  •  無奈伤痛
    2020-12-29 05:20

    HTML:

    First, we will need to add a class to your text container so that we can access and style it accordingly.

    Link up with other gamers all over the world who share the same tastes in games.

    CSS:

    Next, we will apply the following styles to align it vertically, according to the size of the image div next to it.

    .textContainer { 
        height: 345px; 
        line-height: 340px;
    }
    
    .textContainer h3 {
        vertical-align: middle;
        display: inline-block;
    }
    

    All Done! Adjust the line-height and height on the styles above if you believe that it is still slightly out of align.

    WORKING EXAMPLE

提交回复
热议问题