你能看看this demo吗?让我知道为什么我没有在 bootstrap 3 中为按钮的事件状态设置背景颜色?我期望的是在单击后将背景颜色设置为红色,直到鼠标悬停在按钮上,但一旦鼠标离开,它就会再次变为透明!
谢谢
.btn-sample
{
text-shadow: none;
color: white;
background:transparent;
border:2px solid red;
color:red;
}
.btn-sample:hover
{
text-shadow: none;
color: white;
background:red;
}
.btn-sample:active {
box-shadow: none;
background-color: red;
}
.btn-sample.active {
background-color: red;
}
.btn-sample:active:focus {
color: #ffffff;
background-color: red;
}
.btn-sample.active:focus{
background-color: red;
}
.btn-sample:active:focus{
background-color: red;
}
最佳答案
当您单击按钮时,Bootstrap 不会自动附加 active
类。你需要一点 jQuery(或者你可以使用 javascript)来为你做这件事。
试试这个:
$('.btn-sample').click(function() {
$(this).toggleClass('active');
});
关于twitter-bootstrap - 关于设置 Bootstrap 事件按钮背景颜色的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35278675/