I need to change the outline color when the div is selected. I have tried by using the same technique as hover (shown below), but I need help with a selector. Is it possible via JavaScript or is CSS enough?
Here is what I tried:
div { background: #ccc; margin: 20px; } div:hover { outline: 1px solid blue; }
<div>1</div> <div>2</div> <div>3</div>
The outline-color CSS property sets the color of an element's outline.
An outline is a line that is drawn around elements, outside the borders, to make the element "stand out". The outline-color property specifies the color of an outline. Note: Always declare the outline-style property before the outline-color property. An element must have an outline before you change the color of it.
You can try :focus
pseudo-class. Note you will need tabindex
to make your div
s focusable.
div { background: #ccc; margin: 20px; } div:focus { outline: 1px solid blue; }
<div tabindex="-1">1</div> <div tabindex="-1">2</div> <div tabindex="-1">3</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With