我只想使悬停图像的文本可见,并且它应该在悬停图片旁边(左/右)的灰色空间中(而不是在灰色空间之外的图片下方)。
只有css才有可能吗?
如果不是我需要什么?javascript?
HTML
<div class="pictures">
<div class="pic">
<img class="inner-img" src="http://www.csstutorial.net/wp-content/uploads/2010/01/045.png"/><p>This is a beautiful flower!</p>
</div>
<div class="pic">
<img class="inner-img" src="http://www.csstutorial.net/wp-content/uploads/2010/01/045.png"/><p>This is a beautiful flower!</p>
</div>
<div class="pic">
<img class="inner-img" src="http://www.csstutorial.net/wp-content/uploads/2010/01/045.png"/><p>This is a beautiful flower!</p>
</div>
<div class="pic">
<img class="inner-img" src="http://www.csstutorial.net/wp-content/uploads/2010/01/045.png"/><p>This is a beautiful flower!</p>
</div>
<div class="pic">
<img class="inner-img" src="http://www.csstutorial.net/wp-content/uploads/2010/01/045.png"/><p>This is a beautiful flower!</p>
</div>
<div class="pic">
<img class="inner-img" src="http://www.csstutorial.net/wp-content/uploads/2010/01/045.png"/><p>This is a beautiful flower!</p>
</div>
<div class="pic">
<img class="inner-img" src="http://www.csstutorial.net/wp-content/uploads/2010/01/045.png"/><p>This is a beautiful flower!</p>
</div>
</div>
CSS
.pictures {
background-color:rgba(25, 25, 25, 0.3);
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5);
--width: 960px;
float:left;
margin: 0 auto;
position:relative;
left:100px;
transition: all 0.5s ease;
-webkit-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
}
.pictures:hover {
left:40px;
}
.pic {
width:100px;
height:100px;
float:left;
margin:5px;
position: relative;
right: 0;
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5);
background-color:rgba(25, 25, 25, 0.7);
transition: all 0.5s ease;
-webkit-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
color:blue;
border-radius: 3px;
/*abgerundete Ecken*/
}
.pic:hover {
width:210px;
height:210px;
margin:5px 115px 0px -105px;
right: -110px;
}
.inner-img {
width:100%;
}
在jsFiddle上的工作示例。