Selectors
A selector is a component that selects HTML elements. You can use a selector to target HTML elements on a web page.
Here is an example of a selector:
There are several types of CSS selectors:
/* Element Selector */
p {
ㅤcolor: blue;
}
/* ID Selector */
#header {
ㅤbackground-color: black;
}
/* Class Selector */
.highlight {
ㅤbackground-color: yellow;
}
/* Attribute Selector */
[type="text"] {
ㅤborder: 1px solid gray;
}
/* Pseudo-class Selector */
a:hover {
ㅤcolor: red;
}
/* Pseudo-element Selector */
p::first-line {
ㅤfont-weight: bold;
}
These are just a few examples of the many selectors available in CSS. Understanding and using selectors effectively is key to writing efficient and maintainable CSS code.