简体   繁体   English

火狐浏览器取代了背景径向渐变

[英]background radial gradient is displaced in Firefox

I have a dropdown menu where I separated the second-level menu items by a "fancy line" ( <hr> tag ). 我有一个下拉菜单,其中的第二级菜单项之间用“花线”( <hr>标签)隔开。 It's working in all browsers except Firefox, in which the separators are displaced outside the dropdown menu. 它适用于除Firefox以外的所有浏览器,在Firefox中,分隔符位于下拉菜单之外。

I've looked for coding errors everywhere but cannot seem to find any. 我到处都在寻找编码错误,但似乎找不到任何错误。

Can anybody help, please? 有人可以帮忙吗?

My CSS code: 我的CSS代码:

hr.fancy-line {
    border: 0;
    height: 1px;
}

hr.fancy-line:before {
    top: -0.5em;
    height: 1em;
}

hr.fancy-line:after {
    content:'';
    height: 0.5em;
    top: 1px;
    background: initial;    
}

hr.fancy-line:before, 
hr.fancy-line:after {
    content: '';
    position: absolute;
    width: 100%;
}

hr.fancy-line, 
hr.fancy-line:before {  
    background: -moz-radial-gradient(center, ellipse cover, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 75%);
    background: -webkit-gradient(radial, center center, 0px, center center, 75%, color-stop(0%, rgba(0, 0, 0, 0.1)), color-stop(75%, rgba(0, 0, 0, 0)));
    background: -webkit-radial-gradient(center, ellipse cover, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 75%);
    background: -o-radial-gradient(center, ellipse cover, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 75%);
    background: -ms-radial-gradient(center, ellipse cover, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 75%);
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 75%);
}   

You missed the position: relative to the parent, because the position: absolute will be attached to the inmediate relative parent (if not, viewport): 您错过了position: relative对于父级的position: absolute ,因为position: absolute将附加到中间相对父级(如果不是,则为视口):

https://jsfiddle.net/ks2gtpab/ https://jsfiddle.net/ks2gtpab/

hr.fancy-line {
    border: 0;
    height: 1px;
    position:relative;
}

The other browsers seems to be wrong in behaviour, even if you think the bug is in firefox, it's because you set top: 1px , and this calculation will be made by the relative parent or viewport if there are not relative parent. 其他浏览器的行为似乎是错误的,即使您认为该错误是在firefox中也是如此,这是因为您设置了top: 1px ,并且该计算将由相对父对象或视口(如果没有相对父对象)进行。

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

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