
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
Selecting Child Elements with CSS
The CSS child combinator is used to select all child elements of a parent element.
The syntax of the CSS child combinator is as follows −
Selector > Selector { attribute: /*value*/ }
The CSS descendant combinator is used to select all descendants of a parent element
The syntax of the CSS descendant combinator is as follows −
Selector Selector { attribute: /*value*/ }
Example
The following examples illustrate the CSS child and descendant combinator.
<!DOCTYPE html> <html> <head> <style> article > * { text-align: center; border: 10px groove tomato; } ::first-line { box-shadow: inset 0 0 7px cornflowerblue; } </style> </head> <body> <article> <h2>Donec rutrum a erat vitae interdum. </h2> <p>Duis consequat aliquet leo, quis aliquam ex vehicula in. Vivamus placerat tincidunt hendrerit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque semper ex eget nulla consectetur varius.</p> <img src="https://images.unsplash.com/photo-1612840666989- a16302e84978?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=120&ixlib=rb1.2.1&q=80&w=120" /> </article> </body> </html>
Output
This will produce the following result −
Example
<!DOCTYPE html> <html> <head> <style> body > * { margin: 20px; } article p { font-size: 24px; box-shadow: -10px 1px 0 rgba(12,43,180, 0.6); } </style> </head> <body> <article> <p>Neque porro quisquam </p> <p>est qui dolorem ipsum quia dolor sit amet,</p> <div><p>consectetur, adipisci velit.....</p></div> </article> <div> <p> consectetur, adipisci velit</p> <article> <p> consectetur, adipisci velit</p> </article> </div> </body> </html>
Output
This will produce the following result −
- Related Articles
- Selecting Sibling Elements with CSS
- Style every elements that is the last child of its parent with CSS
- Style every elements that is the first child of its parent with CSS
- How to select all child elements recursively using CSS?
- CSS Child Selector
- Overlap Elements with CSS
- Floating Elements with CSS
- Selecting Elements from Lists in Perl
- Child Selectors in CSS
- Selects all elements inside elements with CSS
- Selects all elements with CSS
- Selects all elements and all elements with CSS
- Style every element that is the child of its parent, counting from the last child with CSS
- How to select “last child” with a specific class using CSS?
- Add shadow to elements with CSS

Advertisements