CSS na asali: Zaɓin Abubuwan Abu, ID da Class

A cikin CSS, zaku iya zaɓar abubuwa, class, da kuma id amfani da salo da keɓance abubuwa akan shafin yanar gizonku. Ga cikakken jagora kan yadda ake amfani da su:

 

Zaɓan Abubuwa

Don zaɓar duk misalan takamaiman abin HTML, yi amfani da sunan kashi azaman mai zaɓi. Misali, p yana zaɓar duk <p> alamun da ke cikin takaddar.

 

Zaba Class

Don zaɓar abubuwa masu aji ɗaya, yi amfani da digo "." biye da sunan ajin. Misali, .my-class yana zaɓar duk abubuwa tare da ajin my-class.

Don zaɓar abubuwa tare da azuzuwan da yawa, yi amfani da ɗigo "." kuma jera sunayen ajin da aka raba ta sarari. Misali, .class1.class2 yana zaɓar abubuwa tare da duka biyu class1 da class2 azuzuwan.

 

Zaba id

Don zaɓar wani takamaiman abu ta hanyar sa id, yi amfani da zanta "#" sannan kuma abubuwan id. Misali, #my-id ya zaɓi kashi tare da id my-id.

 

Haɗa Element, Class, da ID Zaɓuɓɓuka

Kuna iya haɗa kashi, class, da zaɓin id don ƙaddamar da takamaiman abubuwa tare da takamaiman azuzuwan da ID.

Misali, div.my-class#my-id ya zaɓi <div> kashi tare class my-class  da ID my-id.

Ga takamaiman misali na zabar abubuwa, class, da id a cikin CSS:

/* Select all <p> tags */  
p {  
  color: blue;  
}  
  
/* Select elements with the class "my-class" */  
.my-class {  
  background-color: yellow;  
}  
  
/* Select the element with the ID "my-id" */  
#my-id {  
  font-weight: bold;  
}  
  
/* Combine element, class, and ID selections */  
div.my-class#my-id {  
  border: 1px solid black;  
}  

Ta amfani da element, class, da zaɓen id, zaka iya zaɓe cikin sauƙi da salon takamaiman abubuwa ko ƙungiyoyin abubuwa akan shafin yanar gizon ku.