Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Style every <p> element that is the only child of its parent with CSS
Use the CSS :only-child selector to style every <p> element that is the only child of its parent.
Example
You can try to run the following code to implement the :only-child selector
<!DOCTYPE html>
<html>
<head>
<style>
p:only-child {
background: orange;
}
</style>
</head>
<body>
<h1>Heading</h1>
<div>
<p>This is a paragraph.</p>
</div>
<div>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</div>
</body>
</html>
Output

Advertisements