- outer container in order to fix the size
- nth-child, in order not to invent classes, or the generation of corresponding javascript styles
- centering of absolutely positioned element
a flat list of pictures as in question, flexible and cross-browser, but at the same time on pure css, perhaps only in a similar way: (you should use the mixin of the preprocessor to fold the duplicate code and maintain such depth as necessary)
gallery-preview { display: block; position: relative; width: 310px; height: 310px; } img { position: absolute; transition: 1s; height: 100%; width: 100%; margin: 0 auto; left: 0; right: 0; } img:nth-child(1) { z-index: 3; height: 100%; width: 100%; top: 0%: } img:nth-child(2) { z-index: 2; height 90%; width: 90%; top: 10%; } img:nth-child(3) { z-index: 1; height 80%; width: 80%; top: 20%; } img:hover { z-index: 5; }
<gallery-preview> <img id="first" src="http://t2.gstatic.com/images?q=tbn:ANd9GcTtwaOFm5x207suB5vq5gM48ii7HjYWWg8TtOGRojCjsjs1VEC0" /> <img id="i2" src="http://4.bp.blogspot.com/-J6yPcDCmk5w/VOsya5JPDiI/AAAAAAAAChA/V3kcmDdbmpQ/s1600/jQuery%2BInterview%2BQuestions%2Band%2BAnswers.png" /> <img id="i3" src="http://centrecon.ru/sites/default/files/field/image/123.jpeg" /> </gallery-preview>
Next, there is the css3 transform: translateZ() , transform: scale() property, as well as other transformations, through which you can make the code even easier by avoiding the need to center something and change the size (perspective) by a single number.
And the most correct decision is to attach pictures to containers recursively (it can be a script):
<div class="cn"> <img src="..."> <div class="cn"> <img src="..."> <div class="cn"> <img src="..."> </div> </div> </div>
Then, the selector will require only two: .cs > img { ... } and .cs > .cs {...} , and the CSS rules are relative.