示例工程 08-box-model
08-box-model/app/style.css
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
*,
*::before,
*::after {
box-sizing: border-box;
}
body,
h1,
h2,
p {
margin: 0;
}
body {
min-height: 100vh;
background: #f8fafc;
color: #0f172a;
font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
line-height: 1.7;
}
.site-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 16px 24px;
border-bottom: 1px solid #e2e8f0;
background: #ffffff;
}
.brand {
font-size: 13px;
font-weight: 700;
letter-spacing: 0.16em;
}
.site-header nav {
display: flex;
gap: 16px;
}
.site-header nav a {
color: #64748b;
font-size: 13px;
text-decoration: none;
}
.site-header nav a:hover,
.site-header nav a:focus-visible {
color: #2563eb;
}
.page {
width: min(100% - 40px, 860px);
margin: 0 auto;
padding: 40px 0 64px;
}
.eyebrow {
color: #64748b;
font-size: 11px;
letter-spacing: 0.18em;
}
h1 {
margin: 6px 0 10px;
font-size: clamp(30px, 5vw, 44px);
line-height: 1.12;
}
.lead {
color: #334155;
font-size: 16px;
}
.panel {
margin-top: 18px;
padding: 24px;
border: 1px solid #e2e8f0;
border-radius: 16px;
background: #ffffff;
}
h2 {
font-size: 19px;
}
.panel p {
margin-top: 8px;
color: #334155;
font-size: 14px;
}
code {
padding: 1px 5px;
border-radius: 4px;
background: #f1f5f9;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 0.9em;
}
/* 1. 四层 */
.margin-layer {
position: relative;
margin-top: 16px;
padding: 22px;
border: 1px dashed #f59e0b;
border-radius: 12px;
background: #fffbeb;
}
.border-layer {
padding: 20px;
border: 6px solid #2563eb;
border-radius: 10px;
background: #eff6ff;
}
.padding-layer {
padding: 18px;
border: 1px dashed #16a34a;
border-radius: 8px;
background: #f0fdf4;
}
.content-layer {
padding: 18px;
border-radius: 6px;
background: #ffffff;
color: #64748b;
font-size: 12px;
text-align: center;
}
.layer-label {
display: block;
margin-bottom: 4px;
color: #64748b;
font-size: 10px;
letter-spacing: 0.08em;
}
/* 2. 尺寸对比 */
.compare {
display: flex;
flex-wrap: wrap;
gap: 24px;
margin-top: 16px;
align-items: flex-start;
}
.demo-box {
width: 260px;
padding: 24px;
border: 4px solid #2563eb;
border-radius: 10px;
background: #eff6ff;
font-size: 12px;
}
.demo-box strong {
display: block;
margin-bottom: 6px;
font-size: 13px;
}
.demo-box span {
color: #475569;
}
.demo-box.content-box {
box-sizing: content-box;
border-color: #f59e0b;
background: #fffbeb;
}
.demo-box.border-box {
box-sizing: border-box;
}
/* 3. 外边距 */
.stack {
display: flex;
flex-direction: column;
gap: 10px;
margin-top: 16px;
}
.stack-item {
padding: 10px 12px;
border: 1px solid #e2e8f0;
border-radius: 8px;
background: #f8fafc;
font-size: 13px;
}
.ratio-box {
position: relative;
width: 100%;
max-width: 420px;
margin-top: 14px;
padding-top: 56.25%;
border-radius: 10px;
background: linear-gradient(135deg, #2563eb, #7c3aed);
overflow: hidden;
}
.ratio-box span {
position: absolute;
inset: 0;
display: grid;
place-items: center;
color: #ffffff;
font-size: 14px;
font-weight: 600;
}
.site-footer {
padding: 20px 24px 36px;
color: #64748b;
font-size: 12px;
text-align: center;
}
@media (max-width: 640px) {
.site-header {
align-items: flex-start;
flex-direction: column;
padding: 14px 18px;
}
.page {
width: min(100% - 28px, 860px);
padding: 28px 0 48px;
}
.panel {
padding: 18px;
}
.demo-box {
width: 100%;
}
}