center vertically the content of a div ( not by line-height )

后端 未结 4 1497
余生分开走
余生分开走 2021-01-26 12:20

I have a div which I need to center vertically its content:

Free coffee for all the people who visit my restaurant&l
4条回答
  •  庸人自扰
    2021-01-26 12:44

    Line-height will give a vertical height to all the lines in the para, since you have absolute positioned div and there is a paragraph inside, you'll need a child div to align them vertically!

    DEMO

    CSS :

    #coffee {
        width: 300px;
    }
    #coffee > .mid {
        margin-top:25%;
        text-align:center
    }
    

    HTML

    Free coffee for all the people who visit my restaurant

提交回复
热议问题