CSS 透明度仅适用于 Mozilla

标签 css

我想制作一个透明的盒子内容,当您将鼠标悬停在上面时它是正常图像。它在不透明的情况下与 Mozilla 配合得很好,但是当我添加其他东西以便它在其他浏览器上工作时,没有任何效果。

.BoxPage a {
  zoom: 1;
  width: 100%;
  /* Theoretically for IE 8 & 9 (more valid) */
  /* ...but not required as filter works too */
  /* should come BEFORE filter */
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=60)";
  /* This works in IE 8 & 9 too */
  /* ... but also 5, 6, 7 */
  filter: alpha(opacity=60);
  /* Older than Firefox 0.9 */
  -moz-opacity: 0.6;
  /* Safari 1.x (pre WebKit!) */
  -khtml-opacity: 0.6;
  /* Modern!
    	/* Firefox 0.9+, Safari 2?, Chrome any?
    	/* Opera 9+, IE 9+ */
  opacity: 0.6!important;
  -ms-filter: ”alpha(opacity=60)”;
  -webkit-opacity: 0.6;
}

.BoxPage a:hover {
  zoom: 1;
  width: 100%;
  /* Required for IE 5, 6, 7 */
  /* ...or something to trigger hasLayout, like zoom: 1; */
  /* Theoretically for IE 8 & 9 (more valid) */
  /* ...but not required as filter works too */
  /* should come BEFORE filter */
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
  /* This works in IE 8 & 9 too */
  /* ... but also 5, 6, 7 */
  filter: alpha(opacity=100);
  /* Older than Firefox 0.9 */
  -moz-opacity: 1;
  /* Safari 1.x (pre WebKit!) */
  -khtml-opacity: 1;
  /* Modern!
    	/* Firefox 0.9+, Safari 2?, Chrome any?
    	/* Opera 9+, IE 9+ */
  opacity: 1!important;
  -ms-filter: ”alpha(opacity=100)”;
  -webkit-opacity: 1;
}
<div class="BoxPage"><a>some text</a></div>

而且透明度仍然只适用于 Mozilla。

最佳答案

简单地:

element {
    opacity: 0;
    transition: opacity 1s ease-out;
}

element:hover {
    opacity: 1;
}

工作示例:

.box {
    width: 100px;
    height: 100px;
    background-color: rgb(255, 0, 0);
    opacity: 0;
    transition: opacity 1s ease-out;
}
    
.box:hover {
    opacity: 1;
}
<h2>Hover over the space below...</h2>

<div class="box"></div>

关于CSS 透明度仅适用于 Mozilla,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46230122/

相关文章:

javascript - 在页面顶部添加特定类到滚动代码

css - child 在整个文档中选择

html - 不存在但存在的边距导致元素下降到新行,因为组合宽度 >100%

javascript - 使用单独的链接显示/隐藏占据相同空间的 div

css - Bootstrap 4 flexbox 导航,带有居中标志和两侧的元素

html - 主 css 搞砸了 bootstrap css

css - meteor /SASS : How to import sass partial into package

javascript - 滚动 : change opacity (from 0 to 1 and vv) of div when at a specific position on page

css - 如何将排水沟添加到纯网格

javascript - ASPX Web 表单中的动态元素 Bootstrap