当使用bootstrap激活时,如何更改按钮颜色? [英] How to change the button color when it is active using bootstrap?

查看:758
本文介绍了当使用bootstrap激活时,如何更改按钮颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是bootstrap 3.当我点击按钮时,我想改变按钮的颜色。我的意思是当它被选择时,按钮应该是不同的颜色。我如何使用css?

I am using bootstrap 3. I want to change button color when I click on button.I mean button should be in different color when it is selected. How can I do this using css?

我的代码是:

<div class="col-sm-12" id="">
    <button type="submit" class="btn btn-warning" id="1">Button1</button>
    <button type="submit" class="btn btn-warning" id="2">Button2</button>
</div>


推荐答案

影响。在您的情况下,您可以使用

CSS has different pseudo selector by which you can achieve such effect. In your case you can use


:活动:如果您只想在按钮被点击时不想坚持。

:active : if you want background color only when the button is clicked and don't want to persist.

:focus :如果您想要背景颜色,直到焦点在按钮上。

:focus: if you want background color untill the focus is on the button.



button:active{
    background:olive;
}

button:focus{
    background:olive;
}

JsFiddle示例

PS:请不要给出 Id html元素的属性。

P.S.: Please don't give the number in Id attribute of html elements.

这篇关于当使用bootstrap激活时,如何更改按钮颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆