html – a元素和button元素的垂直位置

前端之家收集整理的这篇文章主要介绍了html – a元素和button元素的垂直位置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想设置一个< 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/

解决方法

试试这个:-
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

DEMO

原文链接:https://www.f2er.com/html/242599.html

猜你在找的HTML相关文章