html中如何让提交按钮居中?

html-css019

html中如何让提交按钮居中?,第1张

IE6/7及IE8混杂模式中,text- align:center可以使块级元素也居中对齐。其他浏览器中,text-align:center仅作用于行内内容上。

解决这个问题比较好的方式,就是为所有需要相对父容器居中对齐的块级元素设置“margin-left:automargin-right:auto”。但这个方式 IE6/IE7/IE8的混杂模式中不支持,所以还要设置父容器的 "text-align:center"。

若居中对齐的子元素内的行内内容不需要居中对齐,则还需要为其设置“text-align:left”:

<style>

* { font-family:Consolas,Verdana,Arialfont-size:12px}

div, center { border:3px solid dimgraypadding:2px}

span { background:lightgrey}

</style>

<div style="width:200pxtext-align:center">

<div style="width:100pxmargin:0 autotext-align:left">

<span>text</span>

</div>

</div>

html中设置按钮的位置:

解决方案一:

如果是绝对定位,可以设置left,还可通过margin,padding等;

" style="box-sizing: border-boxmargin: 0pxpadding: 0pxfont-family: Menlo, Monaco, Consolas, "Courier New", monospacecolor: rgb(51, 51, 51)font-size: 18.6773pxfont-style: normalfont-variant-ligatures: normalfont-variant-caps: normalfont-weight: normalletter-spacing: normalorphans: 2text-align: starttext-indent: 0pxtext-transform: nonewidows: 2word-spacing: 0px-webkit-text-stroke-width: 0pxbackground-color: rgb(255, 255, 255)"><td style="padding-right:30px"><input type="submit" value="注册"><input type="reset" value="重置"></td></tr>

解决方案二:

如果是绝对定位,可以设置left,还可通过margin,padding等。

参考资料

阿里云.阿里云[引用时间2018-1-9]