- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Role of CSS: first-child Selector
Use the CSS :first-child selector to style every <p> elements that is the first child of its parent.
Example
You can try to run the following code to implement the :first-child selector
<!DOCTYPE html> <html> <head> <style> p:first-child { background-color: orange; } </style> </head> <body> <h1>Heading</h1> <p>This is demo text.</p> <div> <p>This is demo text, with the first child of its parent div.</p> <p>This is demo text, but not the first child.</p> </div> </body> </html>
Advertisements