Sözde sınıflar
Sözde sınıflar, bir öğenin belirli durumlarını veya konumlarını seçmenize izin verir. Örneğin, :hover fare işaretçisi üzerindeyken öğeyi seçer, :focus öğe seçildiğinde veya odağa sahip olduğunda öğeyi seçer, :nth-child() bir gruptaki belirli bir alt öğeyi seçer.
Örnekler:
/* 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;
}
Sözde öğeler
Sözde öğeler, mevcut bir öğeyi özelleştirmek için sanal öğeler oluşturmanıza olanak tanır.
Örneğin, bir öğeden önce ve sonra öğeler oluşturun ::before ve bir öğenin ilk satırını ve ilk harfini seçin. ::after ::first-line ::first-letter
Örnekler:
/* 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;
}
Birleştiriciler
Birleştiriciler, öğeleri ilişkilerine göre seçmek için seçicileri birleştirmenizi sağlar. Örneğin, inside element1 element2 öğesini seçer, öğesinin doğrudan alt öğelerini seçer, öğesinin hemen sonrasını seçer. element2 element1 element1 > element2 element1 element1 + element2 element2 element1
Örnekler:
/* 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;
}
Öznitelik seçiciler
Nitelik seçiciler, öğeleri niteliklerinin değerine göre seçmenize olanak tanır. Örneğin, [attribute] özniteliğine sahip öğeleri seçer attribute, [attribute=value] özniteliği attribute eşittir öğeleri seçer value, [attribute^=value] özniteliği ile attribute başlayan öğeleri seçer value.
Örnekler:
/* 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() seçici
Seçici, belirli bir seçiciyle eşleşmeyen öğeleri seçmenize olanak tanır. Örneğin, sınıfı olmayan öğeleri seçer, kimliği olmayan öğeleri seçer. :not() :not(.class) class :not(#id) id
Örnekler:
/* 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;
}
Bu örnekler, CSS'de gelişmiş öğe seçimini göstermektedir. Web sayfanızdaki öğeleri istediğiniz gibi biçimlendirmek ve özelleştirmek için bu teknikleri özelleştirebilir ve uygulayabilirsiniz.

