Somebody Somebody - 1 month ago 5
CSS Question

Margins only between floated divs

Is it possible to create margin only between floated divs without margins on the sides of parent.

So basically:

no margin <div> |margin| <div> |margin| <div> |margin| <div> no margin
no margin <div> |margin| <div> |margin| <div> |margin| <div> no margin
no margin <div> |margin| <div> |margin| <div> |margin| <div> no margin
no margin <div> |margin| <div> |margin| <div> |margin| <div> no margin
no margin <div> |margin| <div> |margin| <div> |margin| <div> no margin


like that.

Answer

Use the first-child and last-child selectors to specify no left/right margin, respectively:

http://jsfiddle.net/ExplosionPIlls/bzSgp/1

In case you have other elements between the first/last divs, you can use first-of-type/last-of-type instead.