DEV Community

Cover image for Do you know ":first-of-type" in css
Irsyad A. Panjaitan
Irsyad A. Panjaitan

Posted on • Updated on

Do you know ":first-of-type" in css

I think you will need this situation for any reason, for example, if you just want to select the first element after your form-group like label, you can do this technic.

With sass, you can do so:

.form
    &-input, &-textarea
        @apply w-full
    &-group
        @apply mb-4
        label:first-of-type
            @apply block text-gray-700 block mb-2 text-sm
Enter fullscreen mode Exit fullscreen mode

Sorry if you a bit comfused with the @apply, I'm using tailwind css for any property I need.

With css, you can do:

.form-group label:first-of-type {
    property: 'value';
}
Enter fullscreen mode Exit fullscreen mode

That's it, hope this help you :)

Top comments (0)