Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

Group Selectors ใน CSS


คุณสามารถใช้ style เดียวกับหลาย selector ได้ แค่คั่น selector ด้วย comma:

h1, h2, h3 {
  color: #36C;
  font-weight: normal;
  letter-spacing: .4em;
  margin-bottom: 1em;
  text-transform: lowercase;
}

กฎ style นี้จะใช้กับ h1, h2 และ h3 เช่นกัน ลำดับรายการไม่สำคัญ ทุก element ใน selector จะได้ declarations ตรงกัน

คุณสามารถรวม id selectors ได้ดังนี้:

#content, #footer, #supplement {
  position: absolute;
  left: 510px;
  width: 200px;
}