我想让输入的高度与字体大小相同。就像,我希望输入的字体大小为 16 像素,其高度为 16 像素。考虑到没有任何我能看到的东西不会使这成为可能,我认为它是。
正如您将在下面的代码中看到的那样。我已经尽我所能尝试覆盖这种风格。这包括使用 ! 对所有事情都很重要,例如更具体的样式“padding-bottom”而不是“padding”,包括不选择我的元素但应用它们的 CSS 选择器。最重要的是,输入高度的 3px 似乎来自没有样式。
input, input:matches([type="password"], [type="search"]) {
border: none;
padding-top: none !important;
padding-bottom: none !important;
padding-left: none !important;
padding-right: none !important;
margin: none !important;
outline: none;
box-sizing: border-box;
font-size: 16px;
-webkit-appearance: none;
font-weight: normal;
}
<!DOCTYPE html>
<html>
<body>
<input type="text" oninput="myFunction()" style="border: none; padding-top: none !important; padding-bottom: none !important; padding-left: none !important; padding-right: none !important; margin: none !important; outline: none; box-sizing: border-box; font-size: 16px; -webkit-appearance: none; font-weight: normal;">
</body>
</html>
在此处查找与上述相同的代码:https : //codepen.io/AlexStiles/pen/vYBgpGX
根据 Safari 的网络检查器,这是问题(该问题也存在于 Chrome 和 Firefox 中)。似乎样式已失效。请注意,用户代理正在应用一些填充,并且高度是 20 像素而不是 16 像素。我不知道额外的 3px 来自哪里。
注意:我不想为输入设置高度,我希望高度由字体大小决定。
错误...您设置了错误的值
所有真正的语法
/* <length> values */
padding-*: 0.5em;
padding-*: 0;
padding-*: 2cm;
/* <percentage> value */
padding-*: 10%;
/* Global values */
padding-*: inherit;
padding-*: initial;
padding-*: unset;
https://developer.mozilla.org/en-US/docs/Web/CSS/padding-bottom
您可能需要正确设置吗?
padding-top: 0 !important;
padding-bottom: 0 !important;
padding-left: 0 !important;
padding-right: 0 !important;
margin: 0 !important;
如果您需要将行高修剪为与文本大小相同的大小
line-height: 16px;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句