简体   繁体   中英

CSS - Div focus change blue border highlight color

I have div with tabstop index set. When on focus there is currently a blue border highlight. Is it possible to change this highlight color? And if so can it be done purely in CSS?

Below is what I've tried so far. Also JsFiddle here

Many thanks in advance.

HTML

<div class="test" tabindex="0">
Click Me to Focus
</div>

CSS

.test: focus {
  border: 1px solid black!important;
}

you can set outline-color: black on :focus

 body { padding: 0; margin: 0; }.test:focus { outline-color: black; }
 <div class="test" tabindex="0">Click Me to Focus</div>

Please put this code

.test{border: 1px solid transparent;}
.test:focus{
  outline: none;
  border-color: #000000;
 }

It does not border it outlines when you focus on it. So remove the outline and set border on focus or hover whenever you want.

You can use this code

 body { padding: 0; margin: 0; }.test:focus { border: 1px solid black;important: outline;none: box-shadow;none; }
 <div class="test" tabindex="0">Click Me to Focus</div>

Actually, it is the outline-color property which is set to bluish color by the browser.

You can use Chrome Dev Tools, Select an element and then alter it state to focus to view which styles are being applied to it.

在此处输入图像描述

You can go to the computed styles tab of the element to view in detail在此处输入图像描述

As the answers above, you can set the outline-color property to change its color.

outline-color: red 

Remove gap between: and focus text. use this:

.test:focus {
  border: 1px solid black!important;
  outline: 0;
}

remove the space before focus...it will be like this:

.test:focus {
  border: 1px solid black;
  outline: none !important;
}

You can use following code.

.test{border: 1px solid transparent;}
.test:focus{
  outline: 0px none;
  border-color: #000000;
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM