How to remove the border highlight on an input text element

前端 未结 18 1215
庸人自扰
庸人自扰 2020-11-22 05:49

When an HTML element is \'focused\' (currently selected/tabbed into), many browsers (at least Safari and Chrome) will put a blue border around it.

For the layout I a

18条回答
  •  醉梦人生
    2020-11-22 06:49

    In your case, try:

    input.middle:focus {
        outline-width: 0;
    }
    

    Or in general, to affect all basic form elements:

    input:focus,
    select:focus,
    textarea:focus,
    button:focus {
        outline: none;
    }
    

    In the comments, Noah Whitmore suggested taking this even further to support elements that have the contenteditable attribute set to true (effectively making them a type of input element). The following should target those as well (in CSS3 capable browsers):

    [contenteditable="true"]:focus {
        outline: none;
    }
    

    Although I wouldn't recommend it, for completeness' sake, you could always disable the focus outline on everything with this:

    *:focus {
        outline: none;
    }
    

    Keep in mind that the focus outline is an accessibility and usability feature; it clues the user into what element is currently focused.

提交回复
热议问题