views:

24

answers:

2

I have a <div> that is filled with varying block elements (e.g. <p>, <ul>, <ol>, <blockquote>, etc.). I'm looking to control only the spacing between those child block elements. I also want there to be no spacing between the child block elements and the top and bottom of the parent div.

I've played with a few solutions. The main one being a mess of a rule using the adjacent sibling combinator. The other being setting the margin-top value to the desired spacing and then using the :first-child pseudo selector.

Are there any cleaner solutions with a decent amount of compatibility?

Thanks.

A: 

Personally I would make selectors for all child element types separately because CSS3 pseudoclasses are not implemented well in all browsers for now. You can do it this way in the cleanest manner I can think about:

div.class blockquote, div.class p, div.class ul { /* something */ }

etc.

Tomasz Kowalczyk
The adjacent sibling combinator _(aka. `+`)_ is CSS 2 :s Not sure how what you showed can be used to achieve what I want. I'm looking to control the space between a `<div>`'s child block elements and ONLY between themselves. _(e.g. if the `<div>` had 2 `<p>` in it, I want the first to have a 0 top margin and the last to have a 0 bottom margin. Then with either the first or second having a set value for its bottom or top margin respectively. Currently I do this by `p + p { margin-top: whatever }` but the more block elements being used the messier it gets.)_
anomareh
A: 

If i got your point right, shouldn't this suffice?

div * { margin:0 10px }

That * is a bad selector though performance-wise, because of how browsers work: http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/

DanMan