I have below code in html page:
<img id="image_java" alt="image_not" src="images/java-icon.png">
in css page the below code:
#image_java: focus {
outline: 2px solid blue;
}
I have also tried:
img:focus{
outline: 2px solid blue;
}
but non of them seem to work, they are suppose to display a blue margin around the image when focus. Does any one know how to do that? thank you!!!
Hover is for hovering and Focus is for focusing the clicked element.
The :focus selector is used to select the element that has focus. Tip: The :focus selector is allowed on elements that accept keyboard events or other user inputs.
You can target the img tag and not even worry about the div tag. These attribute selectors select by the "begins with". These select by "contains". Or you can select by the exact src.
Actually you CAN focus an <img>
- with the help of tabindex
:
img:focus {
outline: 2px solid blue;
}
<img src="http://www.w3schools.com/images/w3logotest2.png" tabindex="0">
If its an anchor tag you can also use
A:focus img{border: 2px solid blue;}
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