https://codepen.io/dhanushbadge/pen/uJkcq
嗨,我的问题是关于在将鼠标悬停在 img 上时添加添加图标和文本。悬停时它显示灰色,但我希望它也显示 3 个图标和顶部的文本。悬停时,我似乎无法在圆圈内添加文字。原始代码在链接中请帮助pppppppp
html {
font-size:62.5%;
}
body {
margin:0;
font-size:1.4rem;
font-family:arial;
background-color:#ddd;
}
img {
border:0;
width:100%;
height:100%;
}
#team {
max-width:96rem;
width:100%;
min-height:200px;
height:auto;
margin:0 auto;
background-color:white;
box-sizing:border-box;
padding:0;
display:-webkit-flex;
display:flex;
-webkit-align-items:center;
align-items:center;
-webkit-justify-content:center;
justify-content:center;
-webkit-flex-direction:row;
flex-direction:row;
-webkit-flex-wrap:wrap;
flex-wrap:wrap;
-webkit-align-content:flex-end;
align-content:flex-end;
}
figure {
width:12.5rem;
height:12.5rem;
display:block;
margin:0.5rem 1rem 4rem 0.5rem;
padding:0;
box-sizing:content-box;
color:black;
}
figure img {
-webkit-border-radius:50%;
-moz-border-radius:50%;
border-radius:50%;
}
#team figure img {
-webkit-transition:opacity 0.26s ease-out;
-moz-transition:opacity 0.26s ease-out;
-ms-transition:opacity 0.26s ease-out;
-o-transition:opacity 0.26s ease-out;
transition:opacity 0.26s ease-out;
}
#team:hover img, #team:active img {
opacity:1;
}
#team:hover img:hover, #team:active img:active {
opacity:0.3;
}
figcaption {
font-size:1.2rem;
text-align:center;
}
<div id="team">
<figure><img src="http://500px.com/graphics/pages/team/squares/oleg.jpg"><figcaption>Oleg Gutsol</figcaption></figure>
<figure><img src="http://500px.com/graphics/pages/team/squares/evgeny.jpg"><figcaption>Evgeny Tchebotarev</figcaption></figure>
<figure><img src="http://500px.com/graphics/pages/team/squares/dustin.jpg"><figcaption>Dustin Plett</figcaption></figure>
<figure><img src="http://500px.com/graphics/pages/team/squares/adam.jpg"><figcaption>Adam Shutsa</figcaption></figure>
<figure><img src="http://500px.com/graphics/pages/team/squares/roxy.jpg"><figcaption>Roxy Keshavarznia</figcaption></figure>
<figure><img src="http://500px.com/graphics/pages/team/squares/eric.jpg"><figcaption>Eric Akaoka</figcaption></figure>
<figure><img src="http://500px.com/graphics/pages/team/squares/david.jpg"><figcaption>David Charlec</figcaption></figure>
</div>
原文由 Laura Q 发布,翻译遵循 CC BY-SA 4.0 许可协议
有两种方法可以做到这一点:
1. 纯 HTML 和 CSS(没有 Javascript 或 JQuery)
看到 这个小提琴
首先,将文本和图标添加到 HTML 中。看起来您可以将它们添加到
<figure>
块中。其次,添加一个 CSS 规则,仅当图形为
:hover
时才显示这些元素。在此处 了解有关 :hover 伪类的更多信息第三,调整元素的
position
或margins
让它们显示在你想要的地方。2. HTML 和 CSS 和 JQuery
看到 这个其他小提琴
仍然添加具有唯一类的 HTML 元素(我使用“可悬停”)。
仍然将您的 CSS 设置为默认隐藏这些元素。
visibility:hidden;
或display:none;
然后添加一些 JQuery,它
.mouseover()
和.mouseout()
事件以切换元素的可见性或显示。