margin-left: auto and margin-right: auto not working on input

后端 未结 7 1068
闹比i
闹比i 2021-02-01 01:25

I have an input in a form that I am trying to align in the center. Usually margin-left:auto and margin-right: auto fail to respond when display:

7条回答
  •  我在风中等你
    2021-02-01 01:51

    In my case, it was float: left that I forgot about. So, make sure you apply float: none to your input field.

    You already have display: block and margin: 0 auto, you just need to set width too.

    Example that should work:

    input{
         width:50% !important;
         margin:0 auto !important;
         display:block !important;
         float:none !important;
    }
    

    If that doesn't work try adding !important to the values or make sure your style is not overwritten by something else.

提交回复
热议问题