我正在试图弄清楚如何给出一个半透明的图像叠加(出现在:悬停)CSS3过渡(轻松)。但它不起作用。我不确定是不是因为我遗漏了某些东西,或者转换只是不适用于display属性。 CSS解决方法的任何想法(我不知道JavaScript)?提前谢谢。
相关的HTML和CSS:
<div class="thumbnail">
<figure>
<img src="images/dude.jpg" alt=""/>
</figure>
<div class="thumbnail-overlay">
<h2>Project Name</h2>
<h3> Skills Skills Skills</h3>
<p>This is a project description.</p>
</div>
</div>
.thumbnail {
position:relative;
float:left;
width:40%;
margin:1.5% 1.5% 0 0;
}
.thumbnail-overlay {
background-color: @dark-gray;
display:none;
opacity:.9;
position:absolute;
top:0;
left:0;
width:100%; height:100%;
overflow:hidden;
-webkit-transition:all .3s ease;
-moz-transition:all .3s ease;
transition:all.3s ease;
}
.thumbnail:hover .thumbnail-overlay {
display:block;
}
答案 0 :(得分:1)
这可能会对你有所帮助
<div class="tricky"><img class="tricky_image" src="http://distilleryimage11.instagram.com/65c8f832841711e180d51231380fcd7e_7.jpg"></div>
css part:
.tricky {
display:inline-block;
max-width:200px;
max-height:200px;
background:red;
}
.tricky_image {
max-width:200px;
max-height:200px;
-moz-transition: all 1s;
-webkit-transition: all 1s;
-ms-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
opacity:1;
filter:alpha(opacity=100);
}
.tricky_image:hover {
opacity:0.2;
filter:alpha(opacity=20);
}
答案 1 :(得分:0)
因为我看到它是因为显示属性。 css过渡对它不起作用,这就是你遇到这个问题的原因。
这是我测试过的css代码,工作正常:
.thumbnail .thumbnail-overlay {
background-color: @dark-gray;
display:block;
opacity:0;
position:absolute;
top:0;
left:0;
width:100%; height:100%;
overflow:hidden;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.thumbnail:hover .thumbnail-overlay {
opacity: .9;
}
希望它有所帮助!!!
答案 2 :(得分:0)
它对我有用。我将CSS分离到另一个文件并将其链接到HTML文件。它对我很有用
HTML
<head>
<link rel="stylesheet" type="text/css" href="test.css">
</head>
<div class="thumbnail">
<figure>
<img src="/home/qbadmin/Downloads/Pic.jpg" alt=""/>
</figure>
<div class="thumbnail-overlay">
<h2>Project Name</h2>
<h3> Skills Skills Skills</h3>
<p>This is a project description.</p>
</div>
</div>
CSS
.thumbnail {
position:absolute;
float:left;
width:40%;
left :100 px;
top :100px;
margin:1.5% 1.5% 0 0;
}
.thumbnail-overlay {
background-color: @dark-gray;
display:none;
opacity:.9;
position:absolute;
top:100px;
left:100px;
width:100%; height:100%;
overflow:hidden;
-webkit-transition:all .3s ease;
-moz-transition:all .3s ease;
transition:all.3s ease;
}
.thumbnail:hover .thumbnail-overlay {
display:block;
opacity: .9;
}