html的button怎么居中

html的button怎么居中,第1张

如果你的button是button标签的话:<button id="btn">按钮</button>。

拓展:

1、<button>标签定义一个按钮。在 button 元素内部,您可以放置内容,比如文本或图像。这是该元素与使用 input 元素创建的按钮之间的不同之处。<button>控件 与 <input type="button">相比,提供了更为强大的功能和更丰富的内容。<button>与 </button>标签之间的所有内容都是按钮的内容,其中包括任何可接受的正文内容,比如文本或多媒体内容。

2、例如,我们可以在按钮中包括一个图像和相关的文本,用它们在按钮中创建一个吸引人的标记图像。唯一禁止使用的元素是图像映射,因为它对鼠标和键盘敏感的动作会干扰表单按钮的行为。请始终为按钮规定 type 属性。Internet Explorer 的默认类型是 "button",而其他浏览器中(包括 W3C 规范)的默认值是 "submit"。

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]

关键,文字要包含在label标签中,并设置行高,否则文字会与文本框的顶

端对齐。文本框要设置vertical-align:middle否则文本框与button顶端对

齐。button中文字垂直居中,要设置高和行高,行高要小于高。

<html>

<head>

<style type='text/css'>

LABEL

{

LINE-HEIGHT: 20px

HEIGHT: 20px

}

.button

{

font-size:12px

text-align:center

padding:0px

vertical-align:middle

line-height:22px

margin:0px

Height:26px

Width:60px

}

.txt

{

border:1px #6699CC solid

height:20px

width:160px

margin:0px

vertical-align:middle

font-size:12px

padding:0px 2px

line-height :16px

}

</style>

</head>

<body>

div中文字,文本框,button按钮垂直居中对齐方法及的css样式。

<div class="divPad" style="FONT-SIZE: 12pxHEIGHT: 28px">

<label>查询:企业名称</label><input ID="txt_company"

type="text" class="txt" />

<label>姓名</label><input ID="txt_name"

class="txt" Width="80px" type="text"/>

<input type="button" ID="Button1" value="查找"

class="button" /></div>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/6191181.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-17
下一篇 2023-03-17

发表评论

登录后才能评论

评论列表(0条)

保存