CSS play - Focus on images

8th September 2011

For IE8, IE9, Firefox, Opera, Safari and Chrome




  




Photographs copyright ©2011 stu nicholls - taken at Slimbridge - Wildfowl & Wetlands Trust (WWT)



copyright © stu nicholls - CSS play

Information

Whilst producing my previous demo I cam across a way to have :focus, which is allowed on elements that accept keyboard events or other user inputs, to be applied to other elements.

In the above demo, which by the way does not validate, I have applied :focus to the four images so that I can style a mouse click on the 'thumbnail' to produce the large image.

So click the thumbnail to show the large image, then click anywhere on the page to shrink this back to the thumbnail. You can also tab forward and Shift/tab backwards through the images.

This comprised just two lines of style:
.popup {height:96px; cursor:pointer; display:inline; margin-right:3px;}
.popup:focus {position:absolute; height:auto; z-index:100; background:#fff; padding:20px; outline:1px solid #aaa;}

..and just the four images without any extra markup. No links and no wrapping elements:
<img class="popup" src="popbox/pic1.jpg" alt="" tabindex="1" /><img class="popup" src="popbox/pic2.jpg" alt="" tabindex="1" /><img class="popup" src="popbox/pic3.jpg" alt="" tabindex="1" /><img class="popup" src="popbox/pic4.jpg" alt="" tabindex="1" />

Works in IE8+, Firefox, Opera, Safari and Chrome.


Copyright

You may use this method on your personal 'non-profit' web site without seeking my permission. A link back to CSSplay is always appreciated.

Commercial usage is also permitted without seeking approval, but I would ask that a donation is considered to support my work on CSSPlay.

If you are having problems integrating any of my demonstrations into your website then I now offer a service to fault find and correct any errors that you may have introduced. Please email me for more information.



Please Support CSS play

Please note that if your donation is for a demo/menu then you will need to email me with the url of the demo/menu after making the donation

For more CSS demonstrations I recommend that you visit the Dynamic Drive CSS Library.


Free, practical CSS menus, layouts, and examples

Follow CSS play


Facebook   Twitter   Facebook Fan Page