How to align an input tag to the center without specifying the width?

后端 未结 7 1512
不思量自难忘°
不思量自难忘° 2020-12-24 11:30

I have these HTML and CSS:

相关标签:
7条回答
  • 2020-12-24 11:32

    you can put in a table cell and then align the cell content.

    <table>
       <tr>
         <td align="center">
            <input type="button" value="Some Button">
         </td>
       </tr>
    </table>
    
    0 讨论(0)
  • 2020-12-24 11:40

    To have text-align:center work you need to add that style to the #siteInfo div or wrap the input in a paragraph and add text-align:center to the paragraph.

    0 讨论(0)
  • 2020-12-24 11:43

    you can use this two simple line code :

        display: block;
        margin:auto;

    0 讨论(0)
  • 2020-12-24 11:49

    You need to put the text-align:center on the containing div, not on the input itself.

    0 讨论(0)
  • 2020-12-24 11:49

    You can use the following CSS for your input field:

    .center-block {
      display: block;
      margin-right: auto;
      margin-left: auto;
    }
    

    Then,update your input field as following:

    <input class="center-block" type="button" value="Some Button">
    
    0 讨论(0)
  • 2020-12-24 11:53

    You can also use the tag, this works in divs and everything else:

    <center><form></form></center>
    

    This link will help you with the tag:

    Why is the <center> tag deprecated in HTML?

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