示例工程 23-container-queries
23-container-queries/demo-01-card-states/style.css
点击「运行示例」后,左侧显示源码、右侧显示运行结果;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: 26px;
}
.row {
display: flex;
flex-wrap: wrap;
gap: 16px;
margin-top: 18px;
}
.host {
container-type: inline-size;
}
.w-200 { width: 200px; }
.w-340 { width: 340px; }
.w-520 { width: 520px; }
.card {
display: grid;
gap: 10px;
padding: 12px;
border: 1px solid #e2e8f0;
border-radius: 10px;
background: #ffffff;
}
.art {
height: 110px;
border-radius: 6px;
background: linear-gradient(135deg, #2563eb, #7c3aed);
}
.body h2 {
margin: 0;
font-size: 15px;
}
.body p {
margin: 4px 0 0;
color: #64748b;
font-size: 12px;
}
@container (min-width: 300px) {
.card {
grid-template-columns: 88px minmax(0, 1fr);
align-items: start;
}
.art {
height: 100%;
min-height: 88px;
}
}
@container (min-width: 440px) {
.card {
grid-template-columns: 110px minmax(0, 1fr);
align-items: center;
}
.art {
height: 88px;
}
}