简体   繁体   English

Safari 输入文本忽略顶部填充

[英]Safari Input Text Ignores Padding Top

I am having an issue where padding top is being ignored in Safari in an input text box.我遇到一个问题,即输入文本框中的 Safari 中的顶部填充被忽略。 This issue doesn't occur in Chrome, Firefox nor IE. Chrome、Firefox 和 IE 均未出现此问题。 I created a JS Fiddle to display the issue:我创建了一个 JS Fiddle 来显示问题:

http://jsfiddle.net/Xrpwn/5/ http://jsfiddle.net/Xrpwn/5/

If you view this fiddle in Chrome, you can see that the padding-top is rendered correctly.如果您在 Chrome 中查看此小提琴,您可以看到 padding-top 已正确呈现。 However, if you view this fiddle in Safari, the padding-top is ignored and the cursor is by default placed in the vertical center of the input.但是,如果您在 Safari 中查看此小提琴,则 padding-top 将被忽略,并且 cursor 默认位于输入的垂直中心。

For some reason, by default Safari seems to vertically center text in an input.出于某种原因,默认情况下 Safari 似乎在输入中垂直居中文本。 When looking at the source for RenderTextControlSingleLine at http://opensource.apple.com/source/WebCore/WebCore-514/rendering/RenderTextControlSingleLine.cpp it has:http://opensource.apple.com/source/WebCore/WebCore-514/rendering/RenderTextControlSingleLine.cpp查看 RenderTextControlSingleLine 的源代码时,它有:

// For text fields, center the inner text vertically
// Don't do this for search fields, since we don't honor height for them
if (!m_innerBlock) {
currentHeight = innerTextRenderer->height();
if (currentHeight < height())
innerTextRenderer->setLocation(innerTextRenderer->x(), (height() - currentHeight) / 2);
}

I would like to know if anyone knows how to override this behavior using CSS or jQuery or something like that.我想知道是否有人知道如何使用 CSS 或 jQuery 或类似的东西来覆盖此行为。

I don't believe you'll be able to override that behavior, but you could simulate the same effect using something like this http://jsfiddle.net/Xrpwn/7/ (pardon the slop) with a javascript event that captures input:focus/blur to add/remove the outline to the container div.我不相信您将能够覆盖该行为,但您可以使用类似http://jsfiddle.net/Xrpwn/7/ (请原谅斜坡)和捕获输入的 javascript 事件来模拟相同的效果:focus/blur 添加/删除容器 div 的轮廓。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM