[英]How can I show a element on my site when hovered with only JS?
EDIT: 编辑:
Hi, I would like to know how could I show a little X or remove icon when a user hovers over the inbox 嗨,我想知道当用户将鼠标悬停在收件箱上时如何显示X或删除图标
I tried to hide the remove icon first and then add this effect to a <p>
element :hover {display:block;}
,I don't know what I did wrong but it didn't work 我尝试先隐藏删除图标,然后将此效果添加到
<p>
元素中:hover {display:block;}
,我不知道我做错了什么,但是没有用
http://jsbin.com/zijewohoru/1/edit?html,css,output http://jsbin.com/zijewohoru/1/edit?html,css,输出
Is there anyway I could do it with JS or would it be a lot easier to do it with CSS? 无论如何,我可以用JS做到这一点,还是用CSS容易得多?
I think something like this is what you are looking for. 我认为您正在寻找类似这样的东西。
/* Hide icon by default */
.box i {
display: none;
}
/* Show icon on containing element hover */
.box:hover i {
display: block;
}
For a fade-in transition, this would work. 对于淡入过渡,这将起作用。
.box i {
opacity: 0;
-webkit-transition: opacity .3s ease-in;
-moz-transition: opacity .3s ease-in;
-o-transition: opacity .3s ease-in;
-ms-transition: opacity .3s ease-in;
transition: opacity .3s ease-in;
}
.box:hover i {
opacity: 1;
}
Add this 加上这个
.box:hover > i { display: block; } .box > i { display: none; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.