css - Why does text inside a button vertically aligns to middle by default when setting height?
问题描述
Here I'm concerned about the WHY and not "how to vertically align, etc.".
The button and the link have reset styles and look exactly the same with the applied styles, however when adding an explicit height they behave differently.
FWIW the link behaves the same as other elements (e.g. div), the button is the one that has special behaviour.
.btn {
display: inline-block;
border: 1px solid;
font-size: inherit;
font-family: inherit;
color: inherit;
text-decoration: none;
background-color: transparent;
padding: 0;
vertical-align: middle;
height: 100px;
cursor: pointer;
}
<button class="btn"><button></button>
<a class="btn" href=""><a href></a>
解决方案
推荐阅读
- docker - Docker for Windows - 无法列出节点:获取 https://kubernetes.docker.internal:6443/api/v1/nodes:禁止
- javascript - 如何检查 jquery 插件是否已经在 jquery 元素上初始化?
- ruby - Ruby : Watir : 如何避免从 Net::ReadTimeout 关闭浏览器?
- javascript - 在滚动时显示/隐藏 div
- apache-kafka - 是否可以使用 Kafka Producer 实现动态批处理?
- javascript - 在 javascript 中使用适当的回调作为延续
- linux - 退出 bash 脚本而不终止 ssh 连接
- ebpf - 如何使用 iproute2 将 XDP 程序导入内核?
- c++ - 构建树中具有多个 CMakeLists 的 CMakeLists
- encryption - cryptoJS AES 加密返回错误的解密