How to make text inside a button transparent on hover? background should remain the same though

。_饼干妹妹 提交于 2020-01-11 07:43:10

问题


How can one make the text inside a button transparent on hover? the background should remain the same though. I tried opacity:0; but it made the whole button invisible. Help. I tried the below code.

<style>
.btn:hover {
    background-color: #ededed !important;
    color: #3c3c3c !important;
    opacity:0;
}
</style>

<button class=" btn btn-success  btn-lg">test button</button>

回答1:


You need to use an rgba(color,color,color,opacity); for the color rule.

Try this fiddle: https://jsfiddle.net/reala/5xq3mj66/

EDIT: Alright - I think I understand your request.

You want the text to be TRANSLUCENT on hover, (but not invisible, which is 'transparent'), so that you can see the background through the text.

Very similar solution, but change the opacity of rgba to something very low, like 0.3... for example:

.btn:hover {
   color: rgba(0,0,0,0.3);
}

And remember to remove your opacity: 0, or reset it to opacity: 1 - otherwise it will make the entire button transparent. That is not what you want.



来源:https://stackoverflow.com/questions/45308150/how-to-make-text-inside-a-button-transparent-on-hover-background-should-remain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!