* {
box-sizing: border-box;
}
This paragraph is selected using type selector p
.
.type-example p {
color: blue;
}
This paragraph is selected using class selector .class-example
.
.class-example {
color: green;
font-weight: bold;
}
This paragraph is selected using ID selector #id-example
.
#id-example {
color: red;
font-style: italic;
}
input[type="text"] {
border: 2px solid purple;
padding: 5px;
}
This paragraph is inside a div, styled with descendant selector.
.descendant div p {
color: orange;
}
This paragraph is a direct child and styled with >
selector.
This one won't be styled (not a direct child).
.child > p {
color: teal;
}
This paragraph comes right after h3 and is styled.
.adjacent h3 + p {
color: brown;
}
This is a sibling after h4.
This one too!
.sibling h4 ~ p {
color: darkmagenta;
}
.group h1, .group h2 {
color: green;
}