jfox jfox - 24 days ago 11
Sass (Sass) Question

How to use :first-child with tag

This seems like the silliest question, but it has got me stuck. I'm semantically struggling to combine a pseudo selector and tagname with sass

This is what I'm trying to do:

.parent {
&:first-child.. if h4 {
// styles
}
}


I don't want to target all first childs, just those that happen to be a h4.

If it had a class it would just be
&:first-child.class

Answer

You need to insert the tag name before the classname:

h4&:first-child