html - 隐藏一个透明的 :before div on hover

标签 html css pseudo-element

我有一个显示图像的 div,然后有一个半高的半透明 block ,我可以在上面写文本。这是使用该站点中使用“之前”的一些代码完成的。如何在悬停时隐藏这个透明 block ?我已经尝试了所有我能想到的。我不能使用标准的透明图像,因为每个 div 实例上的图像都不同,而且它们不在现场。以这种方式使用 :before 并不是我完全理解的事情,但我怀疑它会使事情复杂化。

.summary_props_trans {
   position: relative; 
   font-family:'Melbourne', Arial, sans-serif;
   font-size: 2vmin;
   color: black;
   font-weight:normal;
   z-index: 0;  
   width: 220px;
   height: 165px;
   margin: 5px;
   float: left;
   padding: 5px 10px 10px 5px;  
   background-repeat: no-repeat;
   background-size:cover;
   border-radius: 4px;
   -webkit-border-radius: 4px;
   -moz-border-radius: 4px;
}

.summary_props_trans:hover {
   filter:alpha(opacity=80);  
   -moz-opacity:0.8;  
   -khtml-opacity: 0.8;  
   opacity: 0.8; 
}

.summary_props_trans:before{
   content:''; 
   display: block;
   position: absolute; 
   background: white; 
   opacity: .5;
   filter:alpha(opacity=50);
   top: 0; right: 0; bottom: 0; left: 0;
   margin: 0px 0px 50px 0px;
   z-index: -1;
}

最佳答案

如果您只是想将样式应用到 .summary_props_trans :before 伪元素,当 .summary_props_trans 元素匹配伪类时,您需要编写 .summary_props_trans:hover:before.summary_props_trans:visited:before 。注意伪元素出现在伪类之后(事实上,在整个选择器的最后)。

所以,简单地添加

.summary_props_trans:hover:before{
    display:none;
}

.summary_props_trans:hover:before {
  filter:alpha(opacity=0);  
  -moz-opacity:0;  
  -khtml-opacity: 0;  
  opacity: 0; 
}

这是一个例子 http://jsfiddle.net/dyaa/kn0z52ya/

关于html - 隐藏一个透明的 :before div on hover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29245086/

相关文章:

html - 为什么在 IE 中文本框不调整到整个 div? Chrome 很好

html - HTML5 中用于概述文档的多级编号标题

css - 将噪声图像混合到 CSS 按钮中的目的是什么?

css - 为什么我可以选择定位伪元素下的文本?

css - 平行对齐 4 个 div,其中一个 div 为空

javascript - 如何在网站加载中为任何标签静音音频/视频?

php - 如何在php中插入css代码?

html - 我可以使用 :before or :after pseudo-element on an input field? 吗

css - 如何将自定义形状或背景添加到当前菜单项的底部

HTML/CSS 布局问题