2016-02-10 34 views
3

我有一个形象,我尽量让最高的50%显示出不同的颜色和文本时,悬停。对于图像高度的较低50%也是如此。 我来到迄今获得低于50%,但其在整个页面,而不仅仅是图像,并且前50%犯规表演。是否有可能实现我的目标?将鼠标悬停在图片顶部和底部有不同的效果

BOOTPLY ...

/* CSS used here will be applied after bootstrap.css */ 
 

 
.image img { 
 
    display: block; 
 
} 
 

 
.thumb-wrap img { 
 
    width: 50%; 
 
    height: auto; 
 
} 
 

 
.thumb-wrap:hover .thumb-caption { 
 
    opacity: 0.7; 
 
} 
 
.thumb-caption { 
 
    position: absolute; 
 
    left: 0px; 
 
    bottom: 0; 
 
    width: 100%; 
 
    height: 50%; 
 
    background-color: #000; 
 
    margin: 0; 
 
    z-index: 1; 
 
    text-align: center; 
 
    opacity: 0; 
 
-webkit-transition: all, .5s; 
 
-moz-transition: all, .5s; 
 
-o-transition: all, .5s; 
 
-ms-transition: all, .5s; 
 
transition: all, .5s; 
 
} 
 
    
 
/*.thumb-caption-above { 
 
    position: absolute; 
 
    left: 0px; 
 
    top: 0; 
 
    width: 100%; 
 
    height: 50%; 
 
    background-color:red; 
 
    margin: 0; 
 
    z-index: 0; 
 
    text-align: center; 
 
    opacity: 0; 
 
-webkit-transition: all, .5s; 
 
-moz-transition: all, .5s; 
 
-o-transition: all, .5s; 
 
-ms-transition: all, .5s; 
 
transition: all, .5s; 
 
}*/
<div class="image"> 
 
         <div class="thumb-wrap"> 
 
          <img src="http://placehold.it/550x150"> 
 

 
          <h2 class="thumb-caption"><a href="#">More info 
 
          </a></h2> 
 
          <h2 class="thumb-caption-above"><a href="#">See larger 
 
          </a></h2> 
 
         </div></div> 
 

 

 
      <div id="push"></div> 
 
    

回答

2

试试这个:

.thumb-wrap { 
 
    width: 550px; 
 
    position: relative; 
 
} 
 

 
.thumb-caption:hover { 
 
    opacity: 0.7; 
 
} 
 

 
/* Default styles for hover block */ 
 
.thumb-caption { 
 
    position: absolute; 
 
    left: 0; 
 
    bottom: 0; 
 
    width: 100%; 
 
    height: 50%; 
 
    background-color: #000; 
 
    margin: 0; 
 
    z-index: 1; 
 
    text-align: center; 
 
    opacity: 0; 
 
    transition: all, .5s; 
 
} 
 

 
/* Alternate positioning and background color */ 
 
.thumb-caption.above { 
 
    top: 0; 
 
    background: red; 
 
} 
 

 
/* For the text color */ 
 
.thumb-caption > a { 
 
    color: blue; /* default */ 
 
} 
 
.thumb-caption.above > a { 
 
    color: yellow; /* alternate */ 
 
}
<div class="image"> 
 
    <div class="thumb-wrap"> 
 
     <img src="http://placehold.it/550x150"> 
 

 
     <h2 class="thumb-caption"><a href="#">More info</a></h2> 
 
     <h2 class="thumb-caption above"><a href="#">See larger</a></h2> 
 
    </div> 
 
</div>

为POSITI的重要组成部分oning是你.thumb-wrap容器元素上添加position: relative。我删除了CSS的浏览器前缀为简洁起见,但你可以在添加他们回来。

+0

谢谢,正是我在后。 – raulbaros

1

下面的示例演示了在同一时间两种替代(信息和缩放),请立即悬停突出的一个。

* { 
 
font-size:1.05em; 
 
color: white; 
 
font-family: arial; 
 
} 
 

 
#image { 
 
width:550px; 
 
height:150px; 
 
position:relative; 
 
background: url('http://i.imgur.com/HNj6tRD.jpg'); 
 
background-repeat: no-repeat; 
 
background-size:100% 100%; 
 
} 
 

 
.coverUP { 
 
\t width: 100%; 
 
\t height: 50%; 
 
\t position:absolute; 
 
\t top:0%; 
 
} 
 

 
.coverDOWN { 
 
\t width: 100%; 
 
\t height: 50%; 
 
\t position:absolute; 
 
\t top:50%; 
 
} 
 

 
.coverUP:hover::after { 
 
background: #cc99ff; 
 
opacity: 0.6; 
 
pointer-events: none; 
 
transition: all, 0.6s; 
 
} 
 

 
.coverDOWN:hover::before { 
 
background: #cc99ff; 
 
opacity: 0.6; 
 
pointer-events: none; 
 
transition: all, 0.6s; 
 
} 
 

 
.coverUP:hover::before { 
 
background: purple; 
 
opacity: 0.8; 
 
pointer-events: none; 
 
transition: all, 0.6s; 
 
} 
 

 
.coverDOWN:hover::after { 
 
background: purple; 
 
opacity: 0.8; 
 
pointer-events: none; 
 
transition: all, 0.6s; 
 
} 
 

 
.coverUP::after { 
 
content: "\A ZOOM"; 
 
white-space: pre; 
 
text-align:center; 
 
\t width: 100%; 
 
\t height: 100%; 
 
\t background: #cc99ff; 
 
\t position:absolute; 
 
\t top:100%; 
 
opacity: 0.0; 
 
pointer-events: none; 
 
transition: all, 0.6s; 
 
} 
 

 
.coverDOWN::before { 
 
content: "\A INFO"; 
 
white-space: pre; 
 
text-align:center; 
 
\t width: 100%; 
 
\t height: 100%; 
 
\t background: #cc99ff; 
 
\t position:absolute; 
 
\t top:-100%; 
 
opacity: 0.0; 
 
pointer-events: none; 
 
transition: all, 0.6s; 
 
} 
 

 
.coverUP::before { 
 
content: "\A INFO"; 
 
white-space: pre; 
 
text-align:center; 
 
\t width: 100%; 
 
\t height: 100%; 
 
\t background: purple; 
 
\t position:absolute; 
 
\t top:0%; 
 
opacity: 0.0; 
 
pointer-events: none; 
 
transition: all, 0.6s; 
 
} 
 

 
.coverDOWN::after { 
 
content: "\A ZOOM"; 
 
white-space: pre; 
 
text-align:center; 
 
\t width: 100%; 
 
\t height: 100%; 
 
\t background: purple; 
 
\t position:absolute; 
 
\t top:0%; 
 
opacity: 0.0; 
 
pointer-events: none; 
 
transition: all, 0.6s; 
 
}
<div id="image" alt=image> 
 
    <a href="#"> 
 
     <div class="coverUP"></div> 
 
    </a> 
 
    <a href="#"> 
 
     <div class="coverDOWN"></div> 
 
    </a> 
 
    </div>

+0

很好!谢谢。 – raulbaros

相关问题