DEV Community

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

Posted on • Edited on

5

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay