Chr*_*ris 3 html css z-index transparent
我几乎在那里,但是a-tag内的文本不应受半透明叠加层的影响:
http://jsfiddle.net/ChrisPrefect/GPLfM/
无论您是否将鼠标悬停在图像上,文本都应为亮白色.
如果需要,我可以添加更多的html元素,但我希望将其保持在最低限度.
添加了一个新元素:
.tint:before
Run Code Online (Sandbox Code Playgroud)
它具有半透明背景:
background: rgba(0,0,0, 0.5);
Run Code Online (Sandbox Code Playgroud)
但是"before"元素也位于a-element内部的文本上并使其变暗.
这可以用z-index排序来解决吗?
谢谢!克里斯
这可以通过正确排序元素来轻松解决.
修复了下面的代码,注意使用相对定位来允许z-indexing和不同的索引.
Jsfiddle样本:http://jsfiddle.net/L8hM9/
body {
color: #fff;
font-family:arial;
}
a {
color:#fff;
position: relative;
}
.block {
display:block;
width:250px;
height:250px;
}
.tint {
z-index: 2;
position: relative;
float: left;
cursor: pointer;
}
.tint:before {
content: "";
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0,0,0, 0.5);
-moz-transition: all .2s linear;
-webkit-transition: all .2s linear;
-ms-transition: all .2s linear;
-o-transition: all .2s linear;
transition: all .2s linear;
z-index:3
}
.tint:hover:before {
background: none;
}
.tint h2, .tint p {
position: relative;
z-index: 4;
}
Run Code Online (Sandbox Code Playgroud)