我不能为我的生活弄清楚如何在图像悬停时让标题文本居中。我尝试了垂直对齐并将其指定为内联块,以不同的方式进行游戏。我觉得我错过了一些明显的东西。
https://jsfiddle.net/b5tmndvk/2/
HTML
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="unit-thumbnail">
<img src="http://i.imgur.com/yIKP2YB.jpg?1" width="100%">
<div class="unit-caption">
<p>Updoot this Stack Overflow post and help me figure this out.</p>
</div>
</div>
</div>
</div>
</div>
CSS
.unit-thumbnail {
position:relative;
overflow:hidden;
}
.unit-caption {
position:absolute;
bottom:-100%;
right:0;
background:rgba(37, 139, 202, 0.75);
width:100%;
height:100%;
padding:2%;
text-align:center;
color:#fff !important;
z-index:2;
-webkit-transition: all 0.9s ease-in-out;
-moz-transition: all 0.9s ease-in-out;
-o-transition: all 0.9s ease-in-out;
-ms-transition: all 0.9s ease-in-out;
transition: all 0.9s ease-in-out;
}
.unit-thumbnail:hover .unit-caption {
bottom:0%;
}
答案 0 :(得分:0)
添加此css
.unit-caption p{
position: relative;
top: 50%;
transform: translateY(-50%);
}