[英]Align text vertically middle of thumbnail image
I have a few thumbnail images that on hover have a multi colored hover styling (looks like this, the yellow thumbnail is what it looks like when you hover over it) 我有一些缩略图图像,这些图像在悬停时具有多种颜色的悬停样式(看起来像这样,当您将鼠标悬停在上面时,黄色的缩略图看起来是这样)
The only problem is that I can't get the text inside to align vertically in the middle of the thumbnail without breaking something else. 唯一的问题是,我无法在不破坏其他内容的情况下使文本在缩略图的中间垂直对齐。 When I change .thumb to display: table;
当我更改.thumb以显示:table; and .align-mid to display: table-cell;
和.align-mid显示:table-cell; with vertical-align: middle;
垂直对齐:中间;垂直 the text aligns to the middle but the background color becomes opaque.
文本与中间对齐,但背景颜色变得不透明。 Looks like this:
看起来像这样:
I can't seem to figure out how to accomplish this. 我似乎无法弄清楚如何做到这一点。
HTML: HTML:
<div class="thumb" onclick="location.href='{{ cms:page:thumb_one.link:string }}'">
{{ cms:page_file:thumb_one.image:image}}
<div class="align-mid">
{{ cms:page:thumb_one.text:string }}<br>
{{ cms:page:thumb_one.description:string }}
</div>
<div class="yellow">
</div>
</div>
CSS: CSS:
.thumb {
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
border-radius: 12px;
display:inline-block;
position: relative;
height: 170px;
width: 235px;
overflow: hidden;
}
.thumb:after {
background: rgba(255,255,255,.7);
content:'';
display: block;
height: 170px;
left: 0;
opacity: 0;
padding: 20px;
position: absolute;
top: 0;
width: 100%;
z-index: 1;
}
.thumb:hover:after {
opacity: 1;
padding: 20px;
transition: opacity .4s;
}
.thumb:hover > .align-mid {
background-color: transparent;
color: white;
}
.thumb:hover {
cursor: pointer;
}
.thumb img {
height: 100%;
width: 100%;
}
.yellow {
opacity: 0;
}
.thumb:hover .yellow {
background: rgba(255,213,43,.8);
content:'';
display: block;
left: 13px;
right: 13px;
bottom: 13px;
top: 13px;
opacity: 1;
position: absolute;
transition: opacity .4s;
z-index: 2;
}
.align-mid {
background-color: rgba(0,0,0,.5);
color: rgb(255,213,43);
height: auto;
padding-top: 10px;
padding-bottom: 10px;
position: relative;
top: -105px;
width: 100%;
z-index: 3;
}
It is obvious that when your wrapper have more than a child , and all children are viewed as table cells , in case you dont want them stacked vertically ( y-axis) , you have to assign absolute positioning to each , this way they gonna be stacked on top of each other ( z-axis) 显然,当包装器中有多个子代时,所有子代都视为表格单元,如果您不希望它们垂直堆叠(y轴),则必须为每个子代分配绝对位置,这样它们就可以彼此堆叠(z轴)
so a simple solution will be: 所以一个简单的解决方案是:
.thumb img { height: 100%; width: 100%; position:absolute; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.