html - a 元素和按钮元素的垂直位置

标签 html css position

我想为 <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>以上:

enter image description here

你可以测试我的 fiddle 中的代码: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

关于html - a 元素和按钮元素的垂直位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26907460/

相关文章:

html - 定位 3 个拆分按钮

html - 需要 CSS 来显示隐藏的表格行。无法弄清楚 Child Sibling 选择器

php - 为什么使用 Spry 菜单会杀死我的 <p> 标签?

html - 如何删除最后一个 child 的边框?

javascript - JS获取对象坐标

view - SwiftUI:如何使用计时器在不同位置创建多个 View ?

javascript - 弹出图像不会停留在同一个地方

html - 如何解决 z-index 问题?

页面的 jQuery 加载主体

CSS3 font-face ...如何制作字体样式 :italic to use the actual italic version?