Consider I have 9 IMG in a html page. They will be rearranged in any number of rows or cells when the viewport of browser changes. What I want is, space between them is 5, but no margin after not at the last row or column.
The margin is not suitable because it gives the last row or column margins too.
Use the :last-child or :first-child directives in your CSS.
For example:
If you use PHP or another server-side scripting language to generate the HTML output, you should better assign IDs (or classes) to the first and last elements there instead of using a pseudo-selector.
If you really want to, you could also combine both.