示例工程 21-media-queries
21-media-queries/demo-02-preferences/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;
}
h2 {
margin: 0 0 6px;
font-size: 14px;
}
.card {
max-width: 560px;
margin-top: 14px;
padding: 16px;
border: 1px solid #e2e8f0;
border-radius: 10px;
background: #ffffff;
}
.card p {
margin: 0;
color: #64748b;
font-size: 13px;
}
.scheme {
background: #ffffff;
color: #0f172a;
}
.motion {
display: flex;
align-items: center;
gap: 10px;
color: #64748b;
font-size: 13px;
}
.dot {
width: 14px;
height: 14px;
border-radius: 50%;
background: #2563eb;
animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.6); opacity: 0.5; }
}
.hover-yes {
display: none;
}
@media (prefers-color-scheme: dark) {
body {
background: #0f172a;
color: #e2e8f0;
}
.card {
border-color: #334155;
background: #1e293b;
}
.card p,
.motion {
color: #94a3b8;
}
.scheme {
background: #020617;
color: #e2e8f0;
}
}
@media (prefers-reduced-motion: reduce) {
.dot {
animation: none;
}
}
@media (hover: hover) {
.hover-no {
display: none;
}
.hover-yes {
display: block;
}
.card:hover {
border-color: #93c5fd;
}
}