CSS3 > Selectors

First-of-type selector in CSS3

How to match every first child of its parent in CSS3?


By using first-of-typeselector we can match the every first child of its parent element.

<style>
        p:first-of-type {
        color:blue;
        background-color:orange;
        font-family:20px;
        }
</style>

<body>
    <strong>This is Strong Statement</strong>
    <p>This is 1st paragraph.</p>
    <p>This is 2nd paragraph.</p>
    <b>This is Bold.</b>
    <div>
        <p>This is the first pargarph in div.</p>
        <p>This is the second paragraph in div.</p>
    </div>
</body>

In the above code snippet we have given style to the <p> element, so that the style applies to the first child of every <p> element.

OUTPUT

 Views: 3246 | Post Order: 21



Write for us






Hosting Recommendations