I have below code in html page:
in css page the below code:
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">
Try using the border property instead of the outline property. It should look like:
img:hover {
border: 2px solid blue;
}
Edit: Use hover instead of focus
If its an anchor tag you can also use
A:focus img{border: 2px solid blue;}
You can't "focus" an image unless you have an interactive element or navigate to it using tab. Try adding an interactive element on a wrapper div like so:
Html
<a class="imageAnchor" href="#">
<img id="image_java" alt="image_not" src="http://www.w3schools.com/images/w3logotest2.png" />
</a>
CSS
.imageAnchor:focus img{
border: 2px solid blue;
}
http://jsfiddle.net/4x7wg7sb/1/