html - 输入高度略大于链接
问题描述
考虑以下示例
https://jsfiddle.net/gq5bru8d/1/
* {
box-sizing: border-box; }
input, a {
background-color: red;
color: white;
border: .1rem solid black;
padding: 1rem;
font-size: 1rem;
line-height: 1rem; }
a {
text-decoration: none; }
<input type="text" placeholder="Input">
<a href="#">Anchor</a>
尽管输入和锚标记都具有相同font-size
的line-height
、padding
和border
,但输入的高度似乎比锚标记大 1px。为什么会这样,你怎么能做到让它们都具有相同的尺寸?
解决方案
将它们包装在一个 flex div 中。
* {
box-sizing: border-box; }
input, a {
background-color: red;
color: white;
border: .1rem solid black;
padding: 1rem;
font-size: 1rem;
line-height: 1rem; }
a {
text-decoration: none;
margin-left: 5px;
}
<div style="display: flex;">
<input type="text" placeholder="Input">
<a href="#">Anchor</a>
</div>
另一种解决方案。将此样式添加到两个元素font: 13.3333px Arial
* {
box-sizing: border-box; }
input, a {
background-color: red;
color: white;
border: .1rem solid black;
padding: 1rem;
font-size: 1rem;
line-height: 1rem;
font: 13.3333px Arial;
}
a {
text-decoration: none;
margin-left: 5px;
}
<input type="text" placeholder="Input">
<a href="#">Anchor</a>
推荐阅读
- mysql - 检索每个组中的最后一条记录 - 按多列分组
- python - 熊猫列值的排序排列?
- c# - 如何从主键中获取对象
- javascript - 在 Promise 中将项目添加到数组时遇到问题
- node.js - 将参数从 Jenkins CI 传递到 npm 脚本
- python - 使用硒从非传统地图中抓取 GIS 坐标?
- wireshark - 如何使用 mbuf 构造 IP 有效负载数据包?
- c++ - 使用 c_str() 或 toCharArray() 将字符串转换为 const char?
- node.js - 在子目录中托管应用程序时的 ExpressJS API 路由
- java - 使用泛型构造子类的实例