加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

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

发布时间:2020-12-14 22:34:14 所属栏目:资源 来源:网络整理
导读:我想设置一个 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: inlin
我想设置一个< 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读