Presented By: Onkar Kale
Presented By: Onkar Kale
A CSS selector can contain more than one simple selector. Between the
simple selectors, we can include a combinator.
The following example selects all <p> elements inside <div> elements:
<style>
div p {
background-color: yellow;
</style>
Child selector (>)
The child selector selects all elements that are the children of a specified element.
The following example selects all <p> elements that are children of a <div> element:
<style>
div > p {
background-color: yellow;
}
</style>
Adjacent Sibling Selector (+)
➢ The adjacent sibling selector is used to select an element that is directly after
another specific element.
➢ Sibling elements must have the same parent element, and "adjacent" means
"immediately following".
<style>
div + p {
background-color: yellow;
}
</style>
General Sibling Selector (~)
The general sibling selector selects all elements that are next
siblings of a specified element.
<style>
div ~ p {
background-color: yellow;
}
</style>
CSS id Selector
#para1 {
text-align: center;
color: red;
</style>
<style>
.center {
text-align: center;
color: red;
</style>
CSS Universal Selector
The universal selector (*) selects all HTML elements on the page.
<style>
*{
text-align: center;
color: blue;
}
</style>
CSS Grouping Selector
The grouping selector selects all the HTML elements with the same style
definitions.
h1, h2, p {
text-align: center;
color: red;
}
</style>