Vertically centering button using css

前端 未结 2 1823
太阳男子
太阳男子 2020-12-29 23:58

I am trying to make a simple input button center-align within a table cell.

My markup is:

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-30 00:40

    http://jsfiddle.net/8v8gLn4y/

    .container {
      background: lightblue;
      display: table;
      width:100%;
    }
            
    input[type=button] {    
      display: block;
      width: 50%;
      margin: 0 auto;
    }
            
    .button-wrapper {
      background: darkorange;
      display: table-cell;
      vertical-align: middle;
    }
    some line with text
    another line with text

    update 2016:
    flexbox

    .container {
      background: bisque;
      display: flex;
      width: 100%;
    }
    
    .container>div {
      flex-grow: 1;
    }
    
    .button-wrapper {
      background: chocolate;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
    
    input[type=button] {
      display: block;
      width: 50%;
      margin: 0 auto;
      flex-shrink: 1;
    }

    some line with text

    another line with text

提交回复
热议问题