gpt4 book ai didi

css - 为什么是:before cannot be seen in safari?

转载 作者:行者123 更新时间:2023-11-28 09:37:57 25 4
gpt4 key购买 nike

我有一个在 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;
}

我不想使用如此疯狂的代码,但我别无选择,因为我正在使用 joomla 2.5

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

在 Safari 中 :before 根本不显示!

Web-site with this problem (不是广告)。

最佳答案

只需添加position:absolute

a:before{
position:absolute;
content:"";
top: 0px;
left: 0px;
.....

并确保你在 a

上有相对位置
#menu li a{
position:relative;
}

例如这个效果很好

#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;
}

对于 css3 dev box-sizing 非常重要

*, *:after, *:before  {
outline: none;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding:0;
margin:0;
}

:before:after 总是position:absolute 并且主要元素应该是position relative

关于css - 为什么是:before cannot be seen in safari?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17989772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com