Vertical align middle on an inline-block anchor tag

后端 未结 5 1551
无人共我
无人共我 2020-12-15 10:11

I have a need for my links and buttons to look the same, but I\'ve been unable to vertically align the text within an \"a\" tag in the same manner as the \"button\" tag. It

5条回答
  •  一向
    一向 (楼主)
    2020-12-15 10:33

    All answers are not updated,and all of them are basically hacks, you should use new CSS3 features, in this case flexbox

    a,button {
      -moz-box-sizing: border-box;
      width: 150px;
      height: 150px;
      display:flex;/*CSS3*/
      align-items:center;/*Vertical align*/
      justify-content:center;/*horizontal align*/
      border: 1px solid #000;
    }
    Testing 1,2,3
        

    That should work for your problem, note that align-items and justify-content will behave the opposite if set flex-direction:vertical, default is flex-direction:row.

    Feel free to use, all browsers support it caniuse.com/#search=flex

    Also check out the free and excellent course flexbox.io/ he is the best teacher at this

    Also check out css-grid, also new in CSS3

提交回复
热议问题