Vertical align text in block element

后端 未结 9 1002
盖世英雄少女心
盖世英雄少女心 2020-12-04 09:53

I know vertical alignment is always asked about, but I don\'t seem to be able to find a solution for this particular example. I\'d like the text centered within the element,

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 10:52

    You can try the display:inline-block and :after.Like this:

    HTML

    
    

    CSS

    li a {
        width: 300px;
        height: 100px;
        margin: auto 0;
        display: inline-block;
        vertical-align: middle;
        background: red;  
    }
    li a:after {
      content:"";
      display: inline-block;
      width: 1px solid transparent;
      height: 100%;
      vertical-align: middle;
    }
    

    Please view the demo.

提交回复
热议问题