我正在製作一個新聞聚合網站的主頁,我們應該有幾個區域將內容與背景中的照片和頂部的文字兩者之間有一個梯度。大多數情況下,除了z-索引較低之外,我還有它,漸變仍然出現在文本框的上方。我已經在堅實的背景下對此進行了嘗試,以確保它的安全。代碼和例子在這裏:http://jsfiddle.net/cx0uvshd/CSS:讓文字出現在我的div中的漸變上方
<style type="text/css">
.feature {
position: relative;
float: left;
width: 465px;
height: 170px;
margin-top: 24px;
margin-right: 30px;
}
.feature.last {
margin-right: 0;
}
.feature-bottom {
background: none;
position: absolute;
bottom: 0;
left: 0;
padding: 0 30px 6px;
width: 100%;
z-index: 200;
line-height: 1;
}
.feature-bottom::after {
content: "";
position: absolute;
bottom: 0px;
left: 0px;
width: 100%;
height: 100%;
z-index: 100;
background: rgba(0,0,0,0);
background: -moz-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(0,0,0,0.5) 50%, rgba(0,0,0,0.5) 100%);
background: -webkit-gradient(left top, left bottom, color-stop(0%, rgba(0,0,0,0)), color-stop(50%, rgba(0,0,0,0.5)), color-stop(100%, rgba(0,0,0,0.5)));
background: -webkit-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(0,0,0,0.5) 50%, rgba(0,0,0,0.5) 100%);
background: -o-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(0,0,0,0.5) 50%, rgba(0,0,0,0.5) 100%);
background: -ms-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(0,0,0,0.5) 50%, rgba(0,0,0,0.5) 100%);
background: linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,0.5) 50%, rgba(0,0,0,0.5) 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#000000', GradientType=0);
}
.feature-bottom h3 {
color: #FFF;
font-size: 15px;
font-weight: 400;
margin: 0;
}
.feature-bottom h2 {
color: #FFF;
font-size: 24px;
font-weight: 400;
margin: 0;
}
</style>
贏家!這很好。非常感謝您的幫助。 – 2015-04-06 20:40:46