[英]Hover effect on button not working - CSS3
Below is my HTML/CSS code in which I am trying to create a similar effect like HOME button as mentioned here - https://codepen.io/larrygeams/pen/pdchG 下面是我的HTML / CSS代码,其中我试图创建类似于HOME按钮的效果,如下所述 - https://codepen.io/larrygeams/pen/pdchG
I made it to a single class, but my code is not working. 我把它写成了一个单独的类,但我的代码不起作用。 Let me know what I am doing wrong here.
让我知道我在这里做错了什么。
.btn-primary { background: green; border: none; border-radius: 10px; padding: 10px 20px; color: #FFF; } .btn-primary:hover { color: #FFF; cursor: pointer; } .btn-primary:after { content: ""; height: 100%; left: 0; top: 0; width: 0px; position: absolute; transition: all 0.3s ease 0s; -webkit-transition: all 0.3s ease 0s; z-index: -1; } .btn-primary:after:hover { background: red; width: 100%; height: 100%; }
<button class="btn-primary" type="submit"> <div class="inner">Add to bag</div> </button>
My Non Working Codepen Link - https://codepen.io/anon/pen/gBdVoj?editors=1100 我的非工作Codepen链接 - https://codepen.io/anon/pen/gBdVoj?editors=1100
hover
pseudo needs to be placed before ::after
hover
pseudo需要放在::after
之前
:hover::after
.btn-primary { width: auto; position: relative; background: green; border: none; border-radius: 10px; padding: 10px 20px; color: #FFF; z-index: 2; } .btn-primary:hover { cursor:pointer; } .btn-primary::after { content: ""; position: absolute; height: 100%; left: 0; top: 0; width: 0; border-radius: 10px; transition: all 0.3s ease 0s; z-index: -1; } .btn-primary:hover::after { width: 100%; background: red; }
<button class="btn-primary" type="submit">Add to bag</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.