It turns out that all it takes is three simple steps
( Demo )
1). Set the left and right margins for each child automatically.
img { margin-left: auto; margin-right: auto; }
2). Set left margin for first child 0
img:nth-child(2) { margin-left: 0; }
3). Set the right margin for last child 0
img:last-child { margin-right: 0; }
If you skip any of these steps, it will not work correctly.
This works in firefox and chrome, I have not tested it in any other browsers.
EDIT:
Thanks @Pontiacks
Apparently you can get away with adding margin-left: auto to img:nth-child(2)
updated jsfiddle
source share