我正在使用bootstrap 3.我想在点击按钮时更改按钮颜色.我的意思是按钮在选中时应该是不同的颜色.我怎么能用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有不同的伪选择器,您可以通过它实现这种效果.在你的情况下你可以使用
:active : if you want background color only when the button is clicked and don’t want to persist.
:focus: if you want background color untill the focus is on the button.
- button:active{
- background:olive;
- }
和
- button:focus{
- background:olive;
- }
P.S.:请不要给出html元素的Id属性中的数字.