CSS Selection

0 55

CSS Selection, bir HTML sayfasında kullanıcı tarafından seçilen metin veya öğeleri stilize etmek için kullanılan bir CSS özelliğidir.

Kullanıcı, bir metin veya öğe grubu seçtiğinde, bu seçim, ::selection seçicisi kullanılarak stilize edilebilir. Örneğin, seçilen metnin rengi, arka plan rengi veya yazı tipi özellikleri gibi özellikler ayarlanabilir.

Aşağıdaki örnek, seçili metnin arka plan rengini mavi, yazı rengini beyaz ve yazı tipini bold olarak ayarlar:

::selection {
    background-color: blue;
    color: white;
    font-weight: bold;
}

Seçim özelliği ayrıca öğe seçiminde de kullanılabilir. Örneğin, bir kullanıcı bir form elemanı seçtiğinde, ::selection seçicisi kullanılarak arka plan rengi veya çerçeve rengi gibi özellikler ayarlanabilir.

input::selection {
    background-color: yellow;
    border: 2px solid green;
}

CSS Selection, web sayfalarının kullanıcı deneyimini geliştirmek için kullanışlı bir özelliktir. Ancak, tarayıcılar arasında farklılık gösterebilir ve bazı tarayıcılarda sınırlı destek sunabilir.

CSS Selection Örnek

HTML ile basit bir paragraf oluşturalım;

<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>

CSS Selection ile paragrafa CSS ekliyelim;

p::selection{
    color: yellow;
    font-weight: bold;
    background: darkblue;
}

HTML ve CSS kodlarını birleştirelim;

<!doctype html>
<html>
    <head>
    <meta charset="utf-8">
        <title>Legal Yazılım</title>
        <style>
            p::selection{
                color: yellow;
                font-weight: bold;
                background: darkblue;
            }    
        </style>   
    </head> 
    <body>
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
        </p>
    </body>
</html>

Çıktısı:

Cevap bırakın

E-posta hesabınız yayımlanmayacak.