为什么 :before 在 safari 中看不到?

Geo*_*ani 5 css safari css-selectors

我有一个在 Chrome 中运行良好的代码:

#menu ul {
list-style-position: inside;
list-style-type: none;
display: block;
margin: 0 auto;
padding: 0;
}
#menu li {
font-size: 11px;
width: 95px;
display: inline-block;
vertical-align: top;
position: relative;
}
#menu li a {
color: black;
text-decoration: none;
}
#menu li a img {
opacity: 0;
filter: alpha(opacity=0);
-moz-opacity: 0;
position: absolute;
top: 0;
left: 22px;
margin: 0 auto;
-webkit-transition: opacity 0.2s linear;
-moz-transition: opacity 0.2s linear;
-o-transition: opacity 0.2s linear;
-ms-transition: opacity 0.2s linear;
}
#menu li a:hover img {
opacity: 1.0;
filter: alpha(opacity=100);
-moz-opacity: 1.0;
}
#menu li a:before {
content: "";
display: block;
background: url('../images/greece.gif') no-repeat center;
width: 50px;
height: 50px;
margin: 0 auto;
opacity: 1.0;
filter: alpha(opacity=100);
-moz-opacity: 1.0;
-webkit-transition: opacity 0.2s linear;
-moz-transition: opacity 0.2s linear;
-o-transition: opacity 0.2s linear;
-ms-transition: opacity 0.2s linear;
}
#menu li.news a:before {
background: url('/images/menu/4.gif') no-repeat center;
}
#menu li a:hover:before {
opacity: 0;
filter: alpha(opacity=0);
-moz-opacity: 0
}
#menu li a span.image-title {
display: block;
padding: 5px;
}
#menu li:hover a, #menu li.current.active a {
color: red;
}
Run Code Online (Sandbox Code Playgroud)

我不想使用如此疯狂的代码,但我没有其他办法,因为我正在使用 joomla 2.5

所以我得到的结果是......在 Firefox 中,不透明过渡不起作用。不,它确实有效,但是以一种奇怪的方式......可以忍受。

在 Safari 中:之前根本不显示!

存在此问题的网站(不是广告)。

Gil*_*mbo 5

只需添加位置:绝对

a:before{
position:absolute;
content:"";
top: 0px;
left: 0px;
.....
Run Code Online (Sandbox Code Playgroud)

并确保你的相对位置

#menu li a{
position:relative;
}
Run Code Online (Sandbox Code Playgroud)

例如,这效果很好

#menu li a:before {
content: "";
display: block;
background: url('../images/greece.gif') no-repeat center;
width: 50px;
height: 50px;
position: absolute;
opacity: 1.0;
filter: alpha(opacity=100);
-moz-opacity: 1.0;
-webkit-transition: opacity 0.2s linear;
-moz-transition: opacity 0.2s linear;
-o-transition: opacity 0.2s linear;
-ms-transition: opacity 0.2s linear;
}
Run Code Online (Sandbox Code Playgroud)

对于 css3 开发 框大小调整非常重要

*, *:after, *:before  {
outline: none;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding:0;
margin:0;
}
Run Code Online (Sandbox Code Playgroud)

:before:after始终是位置:绝对,主要元素应该是相对位置


小智 3

检查一下: http: //caniuse.com/#feat=css-gencontent并检查“已知问题”选项卡。Safari 浏览器不支持伪元素的转换。我昨天面临同样的问题。