简体   繁体   English

Firefox与Chrome填充

[英]Firefox vs Chrome padding

I have a control that I am trying to highlight when it is selected. 我有一个控件,我试图在选中它时突出显示该控件。 I'm achieving this using padding on a div and some positioning so that it surrounds the control. 我使用div上的填充和一些定位来实现此目的,以便它围绕控件。 The problem I'm encountering is that the padding on the highlighter div renders differently in chrome and in firefox. 我遇到的问题是荧光笔div上的填充在chrome和firefox中呈现不同。 Everything I've read says that they render the same so this shouldn't be a problem. 我读过的所有内容都表示它们具有相同的效果,所以这应该不是问题。

Chrome: 铬:

铬:

Firefox: Firefox:

火狐浏览器

Here's a fiddle that has the problem on it: http://jsfiddle.net/5fuGB/1/ 这是一个有问题的小提琴: http : //jsfiddle.net/5fuGB/1/

.control{
    position: absolute;
    width: 100px;
    height: 20px;
    top: 30px;
    left: 300px;
    z-index: 1;
}

.highlighter{
    background-color: orange;
    position: absolute;
    width: 100%;
    height:100%;
    left: -2px;
    top: -2px;
    padding-right: 8px;
    padding-bottom: 10px;
    z-index: -1;
}

input{
    width: 100%;
    height: 100%;
}

My Chrome Version: Version 31.0.1650.63 m on Windows 7 我的Chrome版本:Windows 7上的版本31.0.1650.63 m

My Firefox Version: 25.0 on Windows 7 我的Firefox版本:Windows 7上为25.0

Thanks for any help you guys can offer. 感谢您提供的任何帮助。

I believe the difference you are seeing is a difference which comes from the user agent stylesheet, browsers have their own default stylesheets which they use to render things like input elements. 我相信您看到的区别是来自用户代理样式表的区别,浏览器具有自己的默认样式表,它们可用于呈现input元素之类的内容。 In your case it is probably a difference in the padding applied to the input element. 在您的情况下,应用于input元素的填充可能有所不同。 You should specifically set eg: padding: 0px; 您应该专门设置例如: padding: 0px; or padding: 1px; padding: 1px; on the input element, and then work out how to get it to look right for an input with the specified fixed padding . input元素上,然后找出如何使它看起来正确,并具有指定的固定paddinginput This will then override the styles set by the user agent style sheet. 然后,这将覆盖用户代理样式表设置的样式。

Update 更新资料

I moved to my Windows PC to have a go at fixing it. 我搬到Windows PC上进行修复。 One way to fix this using one of the vendor specific prefixes from the answer linked in the comments is to add -moz-padding-end: 6px; 使用注释中链接的答案中的特定于供应商的前缀之一解决此问题的方法是添加-moz-padding-end: 6px; to .highlighter to compensate for the differences in padding between browsers. .highlighter以补偿浏览器之间的填充差异。

Here's a jsFiddle which fixes your issue, a footnote tho, I can already tell you that this probably won't fix it on Chrome for OSX, which was also rendering things the Firefox way. 这是一个jsFiddle ,它可以解决您的问题,在脚注中,我已经可以告诉您,这可能无法在OSX的Chrome上解决,它也可以通过Firefox渲染。

Another way to fix this is by adding -moz-padding-start: 1px; -moz-padding-end: 1px; 解决此问题的另一种方法是添加-moz-padding-start: 1px; -moz-padding-end: 1px; -moz-padding-start: 1px; -moz-padding-end: 1px; to input , but doing so somehow changes the bottom padding as well, which makes things look not as pretty in Firefox as with the other fix. input ,但这样做也会以某种方式更改底部填充,这使得Firefox中的外观看上去不如其他修补程序那么漂亮。

I'd go about it differently. 我会以不同的方式去做。 Instead of using an extra div, I'd recommend using a combination of border-color and box-shadow on the input's :focus state to achieve the effect you're going for. 建议不要在输入的:focus状态上使用border-colorbox-shadow的组合,以达到所需的效果,而不是使用额外的div。

Check out this modified fiddle: http://jsfiddle.net/5fuGB/2/ 看看这个修改过的小提琴: http : //jsfiddle.net/5fuGB/2/

Just experienced the same issue with my code, and fixed it too. 我的代码遇到了同样的问题,并修复了它。 The trick is if you use display: inline-block then line-height makes sense. 诀窍是如果您使用display:inline-block然后line-height才有意义。 Try it when debugging your code. 在调试代码时尝试一下。

You're doing a little more than what's necessary. 您正在做的事情比必要的要多。 To get a highlight around that input you can use :focus 要突出显示该输入,可以使用:focus

So it would be something like this: 所以会是这样的:

CSS

input {
    border: 1px solid white;
}

input:focus {
    border: 1px solid orange;
}

That will give the input a white "invisible" border so it doesn't move the input when you click into it. 这将为输入提供一个白色的“不可见”边框,因此当您单击输入时,它不会移动输入。 It will simply change the border color to orange to get that highlight effect you're looking for. 只需将边框颜色更改为橙​​色即可获得所需的突出显示效果。

EDIT Just saw your comment. 编辑刚刚看到您的评论。 I dont have the rep to comment so I'll just add on to this. 我没有代表对此做评论,所以我将继续补充。

If you aren't using the inputs as actual inputs, then I would just make them divs. 如果您没有将输入用作实际输入,那么我只是将它们设为div。 Inputs render differently by default so that would mess with consistency across browsers. 默认情况下,输入的呈现方式有所不同,因此会导致浏览器之间的一致性混乱。

I'd also recommend experimenting with those divs within one another and making the most outside div relative. 我还建议您相互之间对这些div进行试验,并使外部div相对最多。

 Outside Div <------ position:relative;
 Middle Div <------- position: absolute;
 Inner div <-------- position: absolute;

Also, if you need a selected state but don't want or are hindered by inputs then I'd recommend jQuery for modifying the css based on user interaction. 另外,如果您需要选定的状态,但又不想输入或被输入所阻碍,那么我建议您使用jQuery基于用户交互来修改CSS。

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

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