div with display:inline-block margin 0 auto not center

后端 未结 3 940
南方客
南方客 2020-12-07 14:13

I try to

相关标签:
3条回答
  • 2020-12-07 14:56

    Try

    body {text-align: center;}
    
    0 讨论(0)
  • 2020-12-07 14:58

    Since you requested DIV to be inline-block, text-align: center; is the answer.

    <div style="text-align: center;">
    <div style="display: inline-block; text-align: left;">
        <input id="abc" type="button" value="button" />
    </div>
    </div>
    
    0 讨论(0)
  • 2020-12-07 15:01

    display:table; would position it in center too:

    CSS:

      .button{
        display: table;
        margin: 0 auto;
        }
    

    HTML:

    <div class="button">
    <input id="abc" type="button" value="button" />
    < /div>
    

    Note: Using inline styles is a bad practice.

    0 讨论(0)
提交回复
热议问题