Kļūda, grupējot sarežģītus CSS selektorus

Viss, kas atdalīts ar komatu grupēšanas laikā, jābūt pilnvērtīgam selektoram. Paskatīsimies, kur šeit var kļūdīties.

Pieņemsim, ka mums ir šāds kods:

css#block h2 {
  color: red;
}
#block h3 {
  color: red;
}

Tagad sagrupēsim divus selektorus vienā. Šeit ir pareizais grupēšanas variants:

css#block h2, #block h3 {
  color: red;
}

Un šeit ir nepareizais grupēšanas variants:

css#block h2, h3 {
  color: red;
}

Šajā nepareizajā grupēšanas variantā iesācējiem kādu iemeslu dēļ šķiet, ka #block attiecas gan uz h2, gan uz h3, kas stāv aiz komata. Bet selektori nedarbojas caur komatu, un faktiski šo nepareizo grupēšanas variantu var pārrakstīt šādi:

css#block h2 {
  color: red;
}
h3 {
  color: red;
}

Salīdziniet ar sākotnējo variantu, kuru mēs sākām saīsināt:

css#block h2 {
  color: red;
}
#block h3 {
  color: red;
}
Задание 1

Vienkāršojiet kodu, izmantojot selektoru grupēšanu:

css#block h1 {
  text-align: center;
}
#block h2 {
  text-align: center;
  color: blue;
}
#block h3 {
  text-align: center;
  font-size: 16px;
  color: red;
}
Задание 2

Vienkāršojiet kodu, izmantojot selektoru grupēšanu:

css#block h1.eee {
  text-align: center;
  font-size: 30px;
}
#block h2.zzz {
  text-align: center;
  font-size: 20px;
}
Задание 3

Vienkāršojiet kodu, izmantojot selektoru grupēšanu:

css.xxx .kkk {
  text-align: center;
}
.eee h2.zzz {
  text-align: center;
}
#eee h2 {
  text-align: center;
}
Задание 4

Vienkāršojiet kodu, izmantojot selektoru grupēšanu:

css.eee h2.zzz {
  text-align: center;
}
.xxx {
  text-align: center;
}