The problem is that you select all div stream elements that are the first child.
In other words, the div streams of the .portlet-borderless-container , .portlet-body and .inner (since they are descendants of the .portlet-dropzone , and they are the first child with respect to their parent element). Since all div elements are selected, each header element is thus selected and styled.
Instead, you need to select the direct child of the div (using the direct child combinator > ). This will only select the div element, which is the direct child of .portlet-dropzone , if it is the first child.
Example here
.layout__side .portlet-dropzone > div:first-child header { padding: 10px; border: 1px solid red; }
As the name suggests, if you also want to choose the latter:
Updated example
.layout__side .portlet-dropzone > div:first-child header, .layout__side .portlet-dropzone > div:last-child header { padding: 10px; border: 1px solid red; }
It is also worth noting that there are :first-of-type and :last-of-type , which will select the first / last element by type (as opposed to :first-child / :last-child , which will select only by index, not by type).
Updated example
.layout__side .portlet-dropzone > div:first-of-type header, .layout__side .portlet-dropzone > div:last-of-type header { padding: 10px; border: 1px solid red; }
This can be useful if there are elements of different types, and you want to target only div elements. For example, if there was a random element h1 before the first div , as in the example above, the first div will be selected.
Josh crozier
source share