Remove outline from select box in FF

2020-01-24 19:06发布

Is it possible to remove the dotted line surrounding a selected item in a select element?

alt text

I have tried to add the outline property in CSS but it did not work, at least not in FF.

<style>
   select { outline:none; }
</style>

Update
Before you go ahead and remove the outline, please read this.
http://www.outlinenone.com/

11条回答
疯言疯语
2楼-- · 2020-01-24 19:49

<select onchange="this.blur();">

If you use this the border stays until you select an item from the list.

查看更多
Animai°情兽
3楼-- · 2020-01-24 19:49
    input[type='range']::-moz-focus-outer {
    border: 0;
    outline: none !important;
    }

working 100%

查看更多
等我变得足够好
4楼-- · 2020-01-24 19:54

Well, Duopixel’s answer is plain perfect. If we go a step further we can make it bulletproof.

select:-moz-focusring {
    color: transparent;
    text-shadow: 0 0 0 #000;
}

There you go, only valid for Firefox and the ugly dotted outline around the selected option is gone.

查看更多
闹够了就滚
5楼-- · 2020-01-24 19:55

This will remove focus from the select element and the outline:

$("select").click(function(){
    $(this).blur();
});

Though this isn't without its shortcomings on other browsers. You'll want to check the browser the user is using:

if (FIREFOX) {
    //implement the code
}
查看更多
家丑人穷心不美
6楼-- · 2020-01-24 19:56

In general, form controls are impossible to style to that degree of accuracy. There's no browser I'm aware of that supports a sensible range of properties in all controls. That's the reason why there're a gazillion JavaScript libraries that "fake" form controls with images and other HTML elements and emulate their original functionality with code:

http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/

...

查看更多
Summer. ? 凉城
7楼-- · 2020-01-24 19:58

This will target all firefox versions

@-moz-document url-prefix() { 
    select {
       color: transparent !important;
       text-shadow: 0 0 0 #000 !important;
    }
}

You might want to remove the !important, if you plan to have the outline appear on other pages across your site that use the same stylesheet.

查看更多
登录 后发表回答