问题是文本没有居中(见下文):
我更改了.text类,使其顶部和左侧为20%,还更改了transform属性和ms-transform属性。但现在的问题是文本不再居中
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 20%;
left: 20%;
transform: translate(-20%, -20%);
-ms-transform: translate(-20%, -20%);
text-align: center;
}
Fade in Overlay
Hover over the image to see the effect.
问题是文本没有居中(见下文):