Pseudo-klase
Pseudoklase vam omogućuju odabir određenih stanja ili položaja elementa. Na primjer, :hover odabire element kada je pokazivač miša iznad njega, :focus odabire element kada je odabran ili ima fokus, :nth-child() odabire određeni podređeni element u grupi.
Primjeri:
/* Select all links when hovered over and change the text color */
a:hover {
color: red;
}
/* Select the <input> element when it is focused and change the border */
input:focus {
border: 2px solid blue;
}
/* Select the second element in a group of <li> elements and change the text color */
li:nth-child(2) {
color: green;
}
Pseudoelementi
Pseudoelementi vam omogućuju stvaranje virtualnih elemenata za prilagodbu postojećeg elementa.
Na primjer, ::before stvorite ::after elemente prije i poslije elementa ::first-line i ::first-letter odaberite prvi redak i prvo slovo elementa.
Primjeri:
/* Add content before each <p> element and style it */
p::before {
content: ">> ";
font-weight: bold;
color: gray;
}
/* Style the first letter of <h1> element */
h1::first-letter {
font-size: 2em;
font-weight: bold;
color: red;
}
Kombinatori
Kombinatori vam omogućuju kombiniranje selektora za odabir elemenata na temelju njihovog odnosa. Na primjer, element1 element2 odabire element2 unutar element1, element1 > element2 odabire izravne podređene elemente od element1, element1 + element2 odabire element2 neposredno nakon element1.
Primjeri:
/* Select <span> elements inside an element with class "container" */
.container span {
color: purple;
}
/* Select <li> elements that are direct children of <ul> */
ul > li {
list-style-type: square;
color: blue;
}
Selektori atributa
Selektori atributa omogućuju odabir elemenata na temelju vrijednosti njihovih atributa. Na primjer, [attribute] odabire elemente s atributom attribute, [attribute=value] odabire elemente s atributom attribute jednakim value, [attribute^=value] odabire elemente s atributom attribute koji počinje s value.
Primjeri:
/* Select all elements with the attribute data-type */
[data-type] {
font-weight: bold;
color: orange;
}
/* Select all <a> elements with the href attribute starting with "https://" */
a[href^="https://"] {
color: blue;
text-decoration: underline;
}
:not() selektor
Selektor vam omogućuje odabir elemenata koji ne odgovaraju određenom selektoru. Na primjer, odabire elemente koji nemaju class, odabire elemente koji nemaju ID. :not() :not(.class) class :not(#id) id
Primjeri:
/* Select all <div> elements that do not have the class "hidden" */
div:not(.hidden) {
display: block;
background-color: lightgray;
}
/* Select all <input> elements that do not have the ID "email-input" */
input:not(#email-input) {
border: 1px solid gray;
}
Ovi primjeri pokazuju napredni odabir elemenata u CSS-u. Ove tehnike možete prilagoditi i primijeniti kako biste stilizirali i prilagodili elemente na svojoj web stranici prema želji.

