CSS Selectors
Overview
CSS selectors are patterns used to select and style HTML elements. Understanding selectors is fundamental to writing effective CSS.
Basic Selectors
Element Selector
css
p {
color: blue;
}Class Selector
css
.highlight {
background-color: yellow;
}ID Selector
css
#header {
font-size: 24px;
}Combination Selectors
Descendant Selector
css
div p {
margin: 10px;
}Child Selector
css
ul > li {
list-style-type: none;
}Adjacent Sibling Selector
css
h1 + p {
margin-top: 0;
}Attribute Selectors
css
input[type="text"] {
border: 1px solid #ccc;
}
a[href^="https"] {
color: green;
}Pseudo-classes
css
a:hover {
color: red;
}
li:first-child {
font-weight: bold;
}