我正在尝试使用不透明度创建淡入淡出过渡(请参阅我的JSFiddle),当您将鼠标悬停在圆圈上时会显示。
如何实现myContent
元素的漂亮淡入?
<div class="circle">
<div class="myContent">
<div class="name">Sasasaas</div>
<div class="position">asfasfasfas</div>
</div>
</div>
这是我正在使用的CSS
.circle {
width: 300px;
height: 300px;
border: 1px black solid;
border-radius: 200px;
background-image: url("http://vignette3.wikia.nocookie.net/yogscast/images/c/c7/Pixel_face_eyebrow_raised_600x600.png/revision/latest/scale-to-width-down/480?cb=20130529234139");
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
margin: auto;
-webkit-filter: grayscale(50%);
-webkit-transition: all 0.5s;
}
.circle:hover {
-webkit-filter: none;
}
.myContent {
opacity: 0;
width: 170px;
height: 170px;
text-align: center;
padding: 15px;
/**position: relative;
visibility: hidden;
-webkit-transition: visibility 0.5s;**/
}
.circle:hover .myContent {
opacity: 1;
}
答案 0 :(得分:2)
尝试以下代码,将转换添加到.mycontent
并设置width as 100%
,然后使用padding-top:50%
和text-align:center
添加padding-top
将文本垂直和水平对齐到图像中心。
.circle {
width: 300px;
height: 300px;
border: 1px black solid;
border-radius: 200px;
background-image: url("http://vignette3.wikia.nocookie.net/yogscast/images/c/c7/Pixel_face_eyebrow_raised_600x600.png/revision/latest/scale-to-width-down/480?cb=20130529234139");
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
margin: auto;
-webkit-filter: grayscale(50%);
-webkit-transition: all 0.5s;
}
.circle:hover {
-webkit-filter: none;
}
.myContent {
opacity: 0;
width: 100%;
height: 170px;
text-align: center;
padding-top: 50%;
transition: 1s ease;
}
.circle:hover > .myContent {
opacity: 1;
}
&#13;
<div class="circle">
<div class="myContent">
<div class="name">Sasasaas</div>
<div class="position">asfasfasfas</div>
</div>
</div>
&#13;