button和a标签设置相同的css样式,但是宽度不同

<button type="submit" class="btn">登录</button>
<a href="/register" class="btn">注册</a>

.btn {
    display: block;
    -moz-appearance: none;
    background: rgba(0, 0, 0, 0) none repeat scroll 0 0;
    border-radius: 0.25rem;
    box-sizing: border-box;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    height: 2rem;
    line-height: 1.9rem;
    margin: 0;
    padding: 0 0.5rem;
    position: relative;
    text-align: center;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 1px solid #f90;
    margin: 0.5em;
    -webkit-user-select: none;
    -moz-user-select: none;
    -moz-transition-duration: 300ms;
    -webkit-transition-duration: 300ms;
    transition-duration: 300ms;
    -webkit-transition-property: background-color;
    transition-property: background-color;
}

这两个元素都使用这个样式,为什么宽度却不一样,bootstrap里好像是可以做到一致的,怎么做到的呢?
我查到好像是浏览器有什么默认样式,怎么能解决这个问题呢?

阅读 6.4k
2 个回答

看看是不是不同的浏览器渲染问题;
把行高统一设置为normal,试一试:

.btn {
    line-height:normal;
    overflow:visible;
}

如果没用的话问一下是啥浏览器

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题