Html 如何在自定义按钮中对齐中心文本?
我有这个htmlHtml 如何在自定义按钮中对齐中心文本?,html,css,Html,Css,我有这个html <head> <title>HTML5 App</title> <link rel="stylesheet" type="text/css" href="css/custom.css"> <link rel="stylesheet" type="text/css" href="css/buttons.css"> </head> <body> <!--Estructura --&g
<head>
<title>HTML5 App</title>
<link rel="stylesheet" type="text/css" href="css/custom.css">
<link rel="stylesheet" type="text/css" href="css/buttons.css">
</head>
<body>
<!--Estructura -->
<div id="botones">
<button class="btn" data-am-type="button">Soy un <button></button>
<a class="btn" data-am-type="button">Soy un <a></a>
<div class="btn" data-am-type="button">Soy un <div></div>
<input class="btn" type="button" value="Soy un <input>">
</div>
</body>
有什么想法吗?要使这些元素的文本垂直居中,只需将元素文本的
行高
设置为元素的高度
,并将框大小
设置为边框框
(以便所有元素的高度
相同:
.btn {
/* other, unchanged, CSS */
line-height: 80px; /* <- changed this */
box-sizing: border-box; /* <- added this */
}
.btn{
/*其他,未更改,CSS*/
行高:80px;/*为.btn类添加一个显示:表格单元格;
像
这将为Div
以及具有class.btn的a
元素创建垂直对齐。
希望这有帮助。请删除
padding:4px12px;
来自btn类
设定
行高:
根据您的要求,文本应位于框的中心。删除此项:高度:80px;
您的填充:padding:4px12px;
移除高度填充后,高度填充必须为~padding:30px 12px;
必须将填充设置为精细(基于文本高度)。我认为为元素设置填充可以创建高度
border: none;
outline: 0;
cursor: pointer;
text-decoration: none;
overflow: visible;
background: none;
padding:0 16px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
color: #222
希望这是有帮助的
vertical-align:center;
使用它,它将工作它应该是,简单地说:行高:0.25em;IE7或更低?标签按钮本身不支持IE7或更低版本。可能你忘了提到它。对吗?@chalist你还忽略了代码片段的一个重要点。即标题标签。它提到了HTML5应用程序。HTML5。你可以写信给提出请求的用户对此进行了编辑,并表示“在IE7或更低版本中不受支持”。对吗?@chalist可能重复的
border: none;
outline: 0;
cursor: pointer;
text-decoration: none;
overflow: visible;
background: none;
padding:0 16px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
color: #222
vertical-align:center;