To select all p elements inside a div element, you can use the descendent selector. The descendant selector allows you to select and style all descendants of an element.
To select all the descendants of an element, you have to simply put white space between the parent and the child. For example, div p
, ul li
, etc.
See this working example:
Example:
div p{ background: yellow; padding: 5px; }
Similarly, you can select all <li> that are inside of a <ul> or <ol>.
See this example:
Example:
ul li{ background: yellow; margin: 5px; }