Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在自定义按钮中对齐中心文本?_Html_Css - Fatal编程技术网

Html 如何在自定义按钮中对齐中心文本?

Html 如何在自定义按钮中对齐中心文本?,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

我有这个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 -->


<div id="botones">
    <button class="btn" data-am-type="button">Soy un &lt;button&gt;</button>
    <a class="btn" data-am-type="button">Soy un &lt;a&gt;</a>
    <div class="btn" data-am-type="button">Soy un &lt;div&gt;</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;