我想将<button>
和<a>
元素设置为相同的格式。我使用以下代码:
button,
a {
border: solid 1px black;
background-color: white;
color: black;
font-family: 'Arial';
padding: 0 15px;
font-size: 13px;
height: 35px;
line-height: 35px;
display: inline-block;
}
#dummy-block {
background-color: black;
padding: 0;
margin: 0;
height: 20px;
}
<div id="dummy-block"></div>
<button>My Button</button>
<a>My Link</a>
但是<button>
元素似乎忽略了高度而我的<a>
元素没有触及上面的黑色虚拟<div>
的边缘:
您可以在我的小提琴中测试代码:http://jsfiddle.net/gyrrcrqc/1/
答案 0 :(得分:3)
试试这个: -
button, a {
background-color: white;
border: medium none;
box-shadow: 0 0 1px #000 inset;
color: black;
display: inline-block;
font-family: "Arial";
font-size: 13px;
height: 35px;
line-height: 35px;
padding: 0 15px;
vertical-align: top;
}
或者: -
button, a {
background-color: white;
border: medium none;
vertical-align:top;
color: black;
display: inline-block;
font-family: "Arial";
font-size: 13px;
height: 35px;
line-height: 35px;
padding: 0 15px;
border:1px solid #000;
box-sizing:border-box
}
<强> DEMO2 强>
答案 1 :(得分:3)
显然,按钮的默认大小调整方法是border-box
,而内联块的默认大小调整方法是content-box
。所以:
<a>
实际上是37px高(边框 添加 2px)<button>
标记高35像素(35px 包含 边框)在两个元素上设置box-sizing: border-box
。
button,
a {
border: solid 1px black;
background-color: white;
color: black;
font-family: 'Arial';
padding: 0 15px;
font-size: 13px;
height: 35px;
line-height: 35px;
display: inline-block;
box-sizing: border-box;
}
#dummy-block {
background-color: black;
padding: 0;
margin: 0;
height: 20px;
}
&#13;
<div id="dummy-block"></div>
<button>My Button</button>
<a>My Link</a>
&#13;
答案 2 :(得分:2)
尝试将vertical-align: bottom
添加到button, a
选择器
button, a
{
border: solid 1px black;
background-color: white;
color: black;
font-family: 'Arial';
padding: 0 15px;
font-size: 13px;
height: 35px;
line-height: 35px;
display: inline-block;
vertical-align: top;
}
#dummy-block
{
background-color: black;
padding: 0;
margin: 0;
height: 20px;
}
<div id="dummy-block"></div>
<button>Okay</button>
<a>Edit</a>
答案 3 :(得分:1)
a
{
padding:1px 15px;
}
button,a
{
border: solid 1px black;
background-color: white;
color: black;
font-family: 'Arial';
font-size: 13px;
height: 35px;
line-height: 35px;
display: inline-block;
}
button
{
padding: 0 15px;
}