Why does margin:0 auto; not work on this input button?

后端 未结 3 531
旧巷少年郎
旧巷少年郎 2021-01-17 17:12

I\'m trying to center an input button within a form but the usual margin: 0 auto; isn\'t doing anything. Here\'s how my HTML is set up:


相关标签:
3条回答
  • 2021-01-17 17:20

    You can add a text-align: center to the input-field, which will automatically horizontally center anything within that element.

    .input-field{
        width:60%;
        margin:0 auto;
        background-color:red;
        text-align:center;
    }
    
    0 讨论(0)
  • 2021-01-17 17:26

    For the margin: auto trick to work, the element must be a block. So, add display: block; to the button css and you'll be fine ;)

    0 讨论(0)
  • 2021-01-17 17:31

    all input elements are inline by default, for applying margin you must use Display: block;

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