2014-09-23 57 views
0

我創建了2個框,在懸停時,褪色爲紅色,但我希望文本保持完全白色並且不會與背景/圖像褪色。我在編碼方面不是很先進,但如果可能的話,任何幫助都會與現場演示一起欣賞?隨着背景顏色從褪色中停止文本

CSS

.image { 
    position:relative; 
    width:400px; 
    height:200px; 
    background-color:#555555; 
    color: #ffffff; 
} 
.image img { 
    width:50%; 
    vertical-align:top; 
    color: #ffffff; 
} 
.image:after, .image:before { 
    position:absolute; 
    background-color:rgba (255,0,0,1); 
    opacity:0; 
    transition: 0.5s ease; 
    -webkit-transition: 0.5s ease; 
    color: #ffffff; 
} 
.image:after { 
    content:'\A'; 
    width:100%; height:100%; 
    top:0; left:0; 
    background-color:rgba(255,0,0,0.75); 
    color:#ffffff; 
} 
.image:before { 
    width:50%; 
    color:#fff; 
    z-index:1; 
    bottom:0; 
    padding:4px 10px; 
    text-align:center; 
    background-color:red; 
    box-sizing:border-box; 
    -moz-box-sizing:border-box; 
    color: rgba(255,255,255,0); 
} 
.image:hover:after, .image:hover:before { 
    opacity:1; 
} 
.text { 
    padding-left:210px; 
    padding-right:10px; 
    margin-top:-190px; 
    color:rgba(255,255,255,10); 
    font-family:Arial; 
    font-size:15px; 
    opacity: 1; 
} 

HTML

<div class="image"> 
    <img src="http://www.newyorker.com/online/blogs/photobooth/NASAEarth-01.jpg" alt="" /> 
    <div class="text"> 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor  incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud.</p> 
    </div> 
</div> 

<hr> 

<div class="image"> 
    <img src="http://www.newyorker.com/online/blogs/photobooth/NASAEarth-01.jpg" alt="" /> 
    <div class="text"> 
     Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud. 
    </div> 
</div> 

回答

0

既然你想保持在前面的文本只使用z-index在你的CSS添加此鏈接:

.text { 
    position:relative; 
    z-index:1; 
} 

入住這Demo Fiddle

如果你想在前面的圖片也使用相同的屬性http://jsfiddle.net/2qekazm4/2/

+0

謝謝丹科 - 正是我在找什麼! – Aaron 2014-09-23 13:51:41

0

在這裏,你去我的朋友,我把這個在小提琴和它的工作奇妙,讓我知道,如果有問題,或者是不是你想要它做。下面是它

http://jsfiddle.net/sps5rxhg/

.image { 
    position:relative; 
    width:400px; 
    height:200px; 
    background-color:#555555; 
    color: #ffffff; 
} 
.image img { 
    width:50%; 
    vertical-align:top; 
    color: #ffffff; 
} 
.image:after, .image:before { 
    position:absolute; 
    background-color:rgba (255,0,0,1); 
    opacity:0; 
    transition: 0.5s ease; 
    -webkit-transition: 0.5s ease; 
    color: #ffffff; 
} 
.image:after { 
    content:'\A'; 
    width:100%; height:100%; 
    top:0; left:0; 
    background-color:rgba(255,0,0,0.75); 
    color:#ffffff; 
} 
.image:before { 
    width:50%; 
    color:#fff; 
    z-index:1; 
    bottom:0; 
    padding:4px 10px; 
    text-align:center; 
    background-color:red; 
    box-sizing:border-box; 
    -moz-box-sizing:border-box; 
    color: rgba(255,255,255,0); 
} 
.image:hover:after, .image:hover:before { 
    opacity:.5; 
} 
.text { 
    padding-left:210px; 
    padding-right:10px; 
    margin-top:-190px; 
    color:rgba(255,255,255,10); 
    font-family:Arial; 
    font-size:15px; 
    opacity: 1; 
     position:relative; 
    z-index:1; 
} 
+2

'color:rgba(255,255,255,10);'?不透明度的參數介於0和1之間 – 2014-09-23 13:46:35

+0

嗨馬克 - 這幾乎是我所追求的,然而是否有可能使圖像褪色以及文本背後的背景而不會使文本本身消失?不知道這是否有道理? – Aaron 2014-09-23 13:48:59

+0

不透明度的範圍不是介於0到1之間,但在0 <= x <= 1時爲0 – 2014-09-23 13:49:03