当使用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;
}
PS:请不要给出html元素的 Id 属性中的数字。
P.S.: Please don't give the number in Id attribute of html elements.