示例工程 03-selectors-basics

03-selectors-basics/demo-02-combinators/style.css

css · 0.8 KB

运行:组合器

点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。

body {
  margin: 0;
  padding: 32px;
  background: #f8fafc;
  color: #0f172a;
  font-family: system-ui, sans-serif;
  line-height: 1.7;
}

h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.box {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #ffffff;
}

.outer {
  margin-top: 8px;
  padding: 8px;
  border: 1px dashed #cbd5e1;
}

.inner {
  margin-top: 8px;
  padding: 8px;
  border: 1px dashed #cbd5e1;
}

/* 后代:所有层级都命中 */
.outer p {
  color: #1e40af;
}

/* 子元素:只命中直接子级 */
.outer > p {
  border-left: 4px solid #2563eb;
  padding-left: 8px;
  font-weight: 600;
}

/* 相邻兄弟:只命中紧挨着的后一个 */
.first + p {
  background: #fef3c7;
  color: #92400e;
}

.third {
  opacity: 0.55;
}