Forum How do I...?

First, Last, and Only Children

jonhall
I seem to have a problem with an only child: I define the first-child and last-child, and I want an only-child to behave like a last-child rather than a first-child (or perhaps differently than both).

I thought I could simply define first-child and then last-child, and since both would apply to an only-child, the latter would take precedence when they conflicted.

When this is in the stylesheet:
section > :first-child { padding: .07in 0in .07in 0in; }
section > :last-child { padding: .07in 0in .375in 0in; }
Prince uses the first-child rule for an only-child. It does the same thing if I put the last-child first or even if I put a separate rule for an only-child first.

How might I fix this?
Thanks, Jonathan
mikeday
I can't seem to reproduce this issue here, if I apply properties to :last-child and :first-child, then an only child gets whichever property is specified last (unless overridden with !important). Can you email me (mikeday@yeslogic.com) a sample document that demonstrates the problem?
jonhall
I discovered my problem. :oops: Here's what didn't work the way I expected:

section > p:first-child {
	page-break-before: avoid;
	padding: .07in 0in .07in 0in;
	text-indent: 0in;
	}

section > :last-child { padding: .07in 0in .375in 0in; }


I figured the last-child padding would apply to an only-child, but I guess the p makes it more specific, and thus overrides the less specific rule for the last-child.

When I added a p to the last-child rule, it worked as expected (or if I took it away from the first-child rule, as I stupidly put in my original post).

Thanks,
Jonathan