Pseudoklasės
Pseudoklasės leidžia pasirinkti konkrečias elemento būsenas ar pozicijas. Pavyzdžiui, :hover pasirenka elementą, kai pelės žymeklis yra virš jo, :focus pasirenka elementą, kai jis yra pasirinktas arba sufokusuotas, :nth-child() pasirenka konkretų antrinį elementą grupėje.
Pavyzdžiai:
/* 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;
}
Pseudoelementai
Pseudoelementai leidžia kurti virtualius elementus esamam elementui pritaikyti.
Pavyzdžiui, ::before ir ::after kurkite elementus prieš ir po elemento ::first-line bei ::first-letter pasirinkite pirmąją elemento eilutę ir pirmąją raidę.
Pavyzdžiai:
/* 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;
}
Kombinatoriai
Kombinatoriai leidžia derinti selektorius, kad pasirinktumėte elementus pagal jų ryšį. Pavyzdžiui, element1 element2 pasirenka element2 viduje element1, element1 > element2 pasirenka tiesioginius antrinius elementus element1, element1 + element2 pasirenka element2 iš karto po element1.
Pavyzdžiai:
/* 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;
}
Atributų parinkikliai
Atributų parinkikliai leidžia pasirinkti elementus pagal jų atributų vertę. Pavyzdžiui, [attribute] pasirenka elementus su atributu attribute, [attribute=value] pasirenka elementus, kurių atributas attribute lygus value, [attribute^=value] pasirenka elementus, kurių atributas attribute prasideda value.
Pavyzdžiai:
/* 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() parinkiklis
Pasirinkiklis leidžia pasirinkti elementus, kurie neatitinka konkretaus parinkiklio. Pavyzdžiui, pasirenka elementus, kurie neturi klasės, pasirenka elementus, kurie neturi ID. :not() :not(.class) class :not(#id) id
Pavyzdžiai:
/* 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;
}
Šie pavyzdžiai parodo išplėstinį elementų pasirinkimą CSS. Galite tinkinti ir pritaikyti šiuos metodus, norėdami stilizuoti ir tinkinti savo tinklalapio elementus, kaip norite.

