Change Bootstrap input focus blue glow

后端 未结 19 2202
抹茶落季
抹茶落季 2020-11-30 16:53

Does anyone know the how to change Bootstrap\'s input:focus? The blue glow that shows up when you click on an input field?

19条回答
  •  悲哀的现实
    2020-11-30 17:22

    I could not resolve this with CSS. It seems like Boostrap is getting the last say even though I have by site.css after bootstrap. In any event, this worked for me.

    $(document).ready(function () {
        var elements = document.getElementsByClassName("form-control");
    
        Array.from(elements).forEach(function () {
            this.addEventListener("click", cbChange, false);
        })
    
        });
    
    function cbChange(event) {
        var ele = event.target;
        var obj = document.getElementById(ele.id);
        obj.style.borderColor = "lightgrey";
    }
    

    Later I found this to work in the css. Obviously with form-controls only

    .form-control.focus, .form-control:focus {
        border-color: gainsboro;
    } 
    

    Here are before and after shots from Chrome Developer tool. Notice the difference in border color between focus on and focus off. On a side note, this does not work for buttons. With buttons. With buttons you have to change outline property to none.

提交回复
热议问题