Combinators si Selectors

postat acum 4 ani de Stefanescu Mihai in categorie CSS

Un combinator este cel ce explica relatia dintre selectori.

Un selector CSS poate contine mai mutle elemente, de fapt intre selectori pot exista si combinatori.Incepand cu CSS3 au aparut diferiti combinatori:

  • descendant selector
  • child selector
  • adjacent sibling selector
  • general sibling selector

Descendant Selector

Acest selector descendent cauta toate elementele descendente unui anumti element.

Urmatorul exemplu selecteaza toate elementele <span> din interiorul unui <div>:

div span{
    background-color: red;

Child Selector

Acest tip de selector cauta toate elementele care sunt “copil” imediat al unui anumit element.

Urmatorul exemplu va afecta toate elementele <span> ce sunt “copil” imediat al elementelor <div>:

div > span {
    background-color: #ff0000;

Adjacent Sibling Selector

Acest tip de selector cauta toate elementele ce sunt inrudite si adiacente ale elementului specificat.

Cand spun inrudit ma refer la faptul ca au acelasi element parinte, iar cand spun adiacent ma refer la elementele ce urmeaza imediat.Urmatorul cod va selecta toate elementele <span> ce sunt amplasate imediat dupa un element <div>:

div + span {
    background-color: #ccc;

General Sibling Selector

Acest tip de selector cauta toate elementele ce sunt inrudite cu un anumit element.

Urmatorul cod selecteaza toate elementele <span> ce sunt inrudite cu elementul <div>:

div ~ span{
    background-color: #00ff00;


Sunt un tanar programator din Bucuresti ce lucreaza in PHP/Mysql (MySqli/PDO), Laravel, CodeIgniter, MySQL, PostgreSQL, Wordpress, HTML5/CSS3, Sass, Photoshop si multe altele.
Google+ Community Facebook Group
Acest articol a fost mutat de pe vechea platforma.
Pentru orice eroare aparuta la mutare va rog sa ma contactati!

Comentariu postate de yeezys la data de 14.05.2019
I needed to draft you the little remark to give many thanks once again with the splendid information you have provided on this site. This is certainly pretty generous of people like you to deliver freely what exactly many people could possibly have advertised as an electronic book in order to make some dough on their own, mostly now that you might have tried it if you ever wanted. Those tips in addition worked like a easy way to be aware that other people have the identical zeal the same as mine to see many more with respect to this matter. I'm certain there are millions of more enjoyable instances up front for individuals who examine your site.