Code highlights logo

Learn

Selectors

Descendant Combinator

In CSS, the descendant combinator is used to target elements that are descendants of another element. It is represented by a space between two selectors.

For example, if you want to target all <p> elements that are inside a <div> element, you can use the following selector:

1div p {
2 /* styles here */
3}

This selector will target all <p> elements that are descendants of a <div> element, no matter how deep they are nested.

You can also use the descendant combinator to target specific descendants of an element, like this:

1div ul li {
2 /* styles here */
3}

This selector will only target <li> elements that are descendants of a <ul> element, which is a descendant of a div element.


Instructions

1.

Select the li elements under the ul element and add a margin-left of 30px.

2.

Select the p element inside the li element with an id of greece and add a color of blue.

3.

Select the img elements inside the li element with an id of italy and add a border of 1px solid black.

Sign up to start coding

Already have an account?

Sign In

Course content