[英]Hover effect on div and image is not working in css
i have a div that contain image [and the image is serve the purpose of button]. 我有一个包含图像的div [该图像用作按钮的目的]。 I want to make the div or img more user freindly .
我想让div或img成为更多用户。 For that i try to create a border when hover on the it .
为此,我尝试在其上悬停时创建一个边框。 But its not working .
但是它不起作用。 Please see my code
请看我的代码
.pa-img, .img-div{ cursor:pointer; } .img-div:hover { border:1px solid red; } .pa-img:hover { border:1px solid red; }
<div class="img-div"> <img class="pa-img" src="https://i.ibb.co/ymCFbTJ/pay-paypal.png" /> </div>
If you have any good idea to make this imge more attractive or more effect on hover please help . 如果您有什么好主意可以使这种效果更吸引人或对悬停产生更多影响,请提供帮助。 I will create a jquery function for the mage click .
我将为mage click创建一个jquery函数。
But currently user is not able to identify this is a button . 但是当前用户无法识别这是一个按钮。 They are not clicking the image .
他们没有点击图片。 That why i try to make hover effect
那就是为什么我试图使悬停效果
Use this, the 1px padding is just so the image does not jump around when you add the border. 使用此功能时,1px填充只是为了使添加边框时图像不会跳来跳去。
.pa-img{
padding: 1px;
}
.pa-img:hover{
padding: 0;
border:1px solid red;
}
I used :hover removed the ::hover placed a transparent border so it wouldn't jump and used a transition so it would move smoothly in and out of hover. 我用:hover删除了:: hover放置了一个透明边框,因此它不会跳转,并使用了一个过渡,以便它可以平稳地移入和移出悬停。
.pa-img, .img-div{ cursor:pointer; border:1px transparent solid; } .img-div:hover{ border:1px solid red; transition:ease-in-out.3s; } .pa-img:hover{ border:1px solid red; transition:ease-in-out.3s; }
<div class="img-div"> <img class="pa-img" src="https://i.ibb.co/ymCFbTJ/pay-paypal.png" /> </div>
You can simply add a transparent border to remove the jumping. 您可以简单地添加透明边框以消除跳跃。 With a simple transitions it's less in your face.
进行简单的转换后,您的脸色就会减少。
.pa-img, .img-div{ cursor:pointer; border: 1px solid transparent; transition: border .2s ease-in-out; } .img-div:hover { border:1px solid red; } .pa-img:hover { border:1px solid red; }
<div class="img-div"> <img class="pa-img" src="https://i.ibb.co/ymCFbTJ/pay-paypal.png" /> </div>
If you want to make it more user-friendly and more aesthetically beautiful, make sure you also get to know a few about Design, and not only coding. 如果要使其更加用户友好和更美观,请确保您还对设计有所了解,而不仅仅是编码。
Here's a way of making it more aesthetically beautiful : 这是使其更美观的一种方法:
.img-div { width: 234px; padding: 10px; } .pa-img, .img-div{ cursor:pointer; border:1px transparent solid; } .img-div:hover{ transition:ease-in-out 0.2s; box-shadow: inset 0px 0px 15px; } .pa-img:hover{ transition:ease-in-out 0.2s; }
<div class="img-div"> <img class="pa-img" src="https://i.ibb.co/ymCFbTJ/pay-paypal.png" /> </div>
ALSO - You can even add rounded borders to make it fit a bit more aesthetically with the PayPal button : 还-您甚至可以使用PayPal按钮添加圆角边框以使其更美观。
.img-div { width: 234px; padding: 10px; border-radius: 25px; } .pa-img, .img-div{ cursor:pointer; border:1px transparent solid; } .img-div:hover{ transition:ease-in-out 0.2s; box-shadow: inset 0px 0px 15px; } .pa-img:hover{ transition:ease-in-out 0.2s; }
<div class="img-div"> <img class="pa-img" src="https://i.ibb.co/ymCFbTJ/pay-paypal.png" /> </div>
IF you want the image also to position a bit to the side and down to work even more like a button, you could do this : 如果您还希望图像也稍微偏向侧面和下方以更像按钮一样工作,则可以执行以下操作:
.img-div { width: 234px; padding: 10px; float: left; } .pa-img, .img-div{ cursor:pointer; border:1px transparent solid; } .img-div:hover{ transition:ease-in-out 0.2s; box-shadow: inset 0px 0px 15px; } .pa-img:hover{ transition:ease-in-out 0.2s; margin-left: 2px; margin-top: 2px; }
<div class="img-div"> <img class="pa-img" src="https://i.ibb.co/ymCFbTJ/pay-paypal.png" /> </div>
To make the rounded borders, just add border-radius: 25px;
要制作圆形边框,只需添加
border-radius: 25px;
(or any value that you prefer) on the .img-div
(或您喜欢的任何值)在
.img-div
I hope it fits your needs. 我希望它适合您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.