【发布时间】:2021-07-10 06:22:13
【问题描述】:
我想在我的图像上获得悬停效果,当用户越过图像时,图像上应该会出现带有一些文本的背景(参见下面的示例)。不幸的是,我的 CSS 看起来一点也不像。它不在中间,图像也不圆,更像一个鸡蛋。
我现在的问题是,我怎样才能使用 CSS 来制作图像,使其呈圆形,并且当翻阅它时,文本可以很好地显示在中间。
我还使用 Bootstrap 作为附加库,如果它应该更容易的话。
我有什么:
我想要什么:
Pic.js
<div class="container-profilepic">
<img src="./image.png" width="150" height="150" alt="Profibild" className="photo-preview"></img>
<div class="middle-profilepic">
<div class="text-profilepic"><i class="fas fa-camera"></i>
<div class="text-profilepic">Change it
</div>
</div>
Photo.css
.photo-preview{
width: 100% !important;
max-width: 125px !important;
height: 100% !important;
max-height: 125px!important;
border-radius: 50% !important;
}
.middle-profilepic {
transition: .5s ease;
opacity: 0;
position: absolute;
text-align: center;
}
.container-profilepic:hover .photo-preview {
opacity: 0.3;
}
.container-profilepic:hover .middle-profilepic {
opacity: 1;
}
.text-profilepic {
color: green;
font-size: 16px;
}
我检查了这个问题之前How do I add animated text on these images when I hover my cursor without changing current style? 不幸的是,它对我没有帮助。
我之前用top、left、postion...
.middle-profilepic {
transition: .5s ease;
opacity: 0;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
结果
所以我删除了它,因为结果更接近我想要的结果
【问题讨论】: