目录

🎯 核心概念速览

⭐ 高分回答模板

第一模块:选择器增强🎯

第二模块:盒模型变化 📦

第三模块:背景与边框 🖼️

第四模块:文字与字体 🔤

第五模块:过渡与动画 🎭

Transition 过渡

Animation 动画

第六模块:变换 Transform🔄

第七模块:布局系统 📐

Flexbox 弹性布局

Grid 网格布局

第八模块:颜色与渐变 🌈

第九模块:媒体查询与响应式 📱

第十模块:其他重要特性 🧩

💡 一句话总结


🎯 核心概念速览

CSS3 是 CSS 的第三个主要版本,采用模块化方式开发,新增了大量特性,极大地增强了网页的表现力和交互能力。

CSS3 新特性全景图
├── 🎨 选择器增强
├── 📦盒模型变化
├── 🖼️ 背景与边框
├──🔤 文字与字体
├── 🎭 过渡与动画
├── 📐 布局系统(Flex/Grid)
├── 🌈 颜色与渐变
├── 🔄 变换 Transform
├── 📱媒体查询
└── 🧩 其他特性

⭐ 高分回答模板

面试官问:CSS3 新增了哪些新特性?


"CSS3 的新特性非常多,我会从选择器、盒模型、视觉效果、动画、布局、颜色、响应式等几个维度系统地讲,并结合实际应用场景说明。"


第一模块:选择器增强🎯

"CSS3 大幅扩展了选择器,让我们无需JS 就能精确定位元素。"

/* ① 属性选择器增强 */
input[type="text"] { border: 1px solid #ccc; }   /* 精确匹配 */
a[href^="https"] { color: green; }                /* 以...开头 */
a[href$=".pdf"] { color: red; }/* 以...结尾 */
a[href*="google"] { font-weight: bold; }          /* 包含... */

/* ② 结构伪类选择器 */
li:first-child { color: red; }          /* 第一个子元素 */
li:last-child { color: blue; }          /* 最后一个子元素 */
li:nth-child(2n) { background: #eee; }  /* 偶数行 */
li:nth-child(2n+1) { background: #fff; }/* 奇数行 */
li:nth-child(3) { font-weight: bold; }  /* 第3个*/
li:nth-last-child(1) { color: gray; }   /* 倒数第1个 */
p:only-child { color: purple; }         /* 唯一子元素 */

/* ③ 类型伪类 */
p:first-of-type { font-size: 1.2em; }   /* 同类型第一个 */
p:last-of-type { font-size: 0.9em; }    /* 同类型最后一个 */
p:nth-of-type(2) { color: red; }        /* 同类型第N个 */

/* ④ 状态伪类 */
input:focus { border-color: #3498db; outline: none; }
input:disabled { background: #f5f5f5; cursor: not-allowed; }
input:checked + label { color: green; }
input:valid { border-color: green; }
input:invalid { border-color: red; }
input:placeholder-shown { background: #fffde7; }

/* ⑤ 否定伪类 */
li:not(.active) { opacity: 0.6; }/* 非.active的li */
p:not(:first-child) { margin-top: 1em; }

/* ⑥ 伪元素(CSS3 规范用双冒号)*/
p::before { content: "→ "; color: #3498db; }
p::after { content: "✓"; color: green; }
p::first-line { font-weight: bold; }    /* 第一行 */
p::first-letter { font-size: 2em; }    /* 首字下沉 */
::selection { background: #3498db; color: white; } /* 选中文字样式 */
::placeholder { color: #999; font-style: italic; } /* 输入框占位符 */

实际应用:斑马纹表格

/* 无需 JS,纯CSS 实现斑马纹*/
tr:nth-child(even) {background-color: #f8f9fa;
}

tr:hover {
  background-color: #e3f2fd;
}

第二模块:盒模型变化 📦

"CSS3 最重要的盒模型变化是引入了 box-sizing 属性。"

/* CSS2 默认(content-box):宽度 = 内容宽,不含padding/border */
.box-old {
  box-sizing: content-box;  /* 默认值 */
  width: 200px;
  padding: 20px;
  border: 2px solid #000;
  /* 实际占宽:200 + 20*2 + 2*2 = 244px ← 让人头疼!*/
}

/* CSS3 推荐(border-box):宽度 = 总宽,含padding/border */
.box-new {
  box-sizing: border-box;   /* 推荐全局设置 */
  width: 200px;
  padding: 20px;
  border: 2px solid #000;
  /* 实际占宽:就是200px✅内容区自动计算 */
}

/* 全局最佳实践 */
*, *::before, *::after {
  box-sizing: border-box;
}

新增盒子相关属性:

.box {
  /*阴影:可叠加多个 */
  box-shadow:
    0 2px 4px rgba(0,0,0,0.1),      /* 外阴影 */
    0 8px 16px rgba(0,0,0,0.1),     /* 外阴影 */
    inset 0 1px 2px rgba(0,0,0,0.2);/* 内阴影 */

  /* 圆角:四角统一 or 单独设置 */
  border-radius: 8px;
  border-radius: 8px 4px 8px 4px;   /* 左上 右上 右下 左下 */
  border-radius: 50%;                /* 圆形 */
  border-top-left-radius: 20px 10px; /* 椭圆圆角 */

  /* 轮廓偏移 */
  outline: 2px solid blue;
  outline-offset: 4px;               /* 轮廓与边框的间距 */

  /* 溢出处理 */
  overflow: hidden;
  overflow-x: scroll;
  overflow-y: hidden;
  resize: both;                       /* 允许用户调整大小 */
}

第三模块:背景与边框 🖼️

.box {
  /* ① 多背景图叠加(CSS3 新增)*/
  background-image:
    url('top-icon.png'),
    url('pattern.png'),
    linear-gradient(135deg, #667eea, #764ba2);
  background-position: top right, center, center;
  background-repeat: no-repeat, repeat, no-repeat;
  background-size: 50px, auto, cover;

  /* ② background-size(CSS3 新增)*/
  background-size: cover;    /* 覆盖,可能裁剪 */
  background-size: contain;  /* 包含,可能留白 */
  background-size: 100% 50%; /* 精确设置 */
  background-size: 200px;    /* 固定宽,高等比*/

  /* ③ background-origin(背景原点)*/
  background-origin: content-box;  /* 从内容区开始 */
  background-origin: padding-box;  /* 从内边距开始(默认)*/
  background-origin: border-box;   /* 从边框开始 */

  /* ④ background-clip(背景裁剪)*/
  background-clip: content-box;
  background-clip: padding-box;
  background-clip: border-box;
  background-clip: text;/* 背景裁剪到文字!*/
  -webkit-background-clip: text;
  color: transparent;               /* 配合文字渐变效果 */
}

/* 边框图片(高级特性)*/
.fancy-border {
  border: 10px solid transparent;
  border-image: url('border.png') 30round;
  border-image-source: url('border.png');border-image-slice: 30;
  border-image-width: 10px;
  border-image-repeat: round;

  /* 渐变边框(常用技巧)*/
  border: 3px solid transparent;
  background:
    linear-gradient(white, white) padding-box,
    linear-gradient(135deg, #667eea, #764ba2) border-box;
}

第四模块:文字与字体 🔤

/* ① @font-face 自定义字体 */
@font-face {
  font-family: 'MyFont';
  src: url('myfont.woff2') format('woff2'),  /* 现代浏览器 */
       url('myfont.woff') format('woff'),    /* 旧浏览器 */
       url('myfont.ttf') format('truetype');font-weight: normal;
  font-style: normal;font-display: swap;                /* 字体加载策略 */
}

.custom-font {
  font-family: 'MyFont', sans-serif;
}

/* ② 文字阴影 */
.text-shadow {
  /* 水平偏移 垂直偏移 模糊半径 颜色 */
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);

  /* 多层阴影叠加(发光效果)*/
  text-shadow:
    0 0 10px #fff,
    0 0 20px #fff,
    0 0 40px #3498db;

  /* 浮雕效果 */
  text-shadow:
    1px 1px 0#fff,
    -1px -1px 0 #999;
}

/* ③ 文字溢出处理 */
/* 单行省略 */
.ellipsis {
  white-space: nowrap;       /* 不换行 */
  overflow: hidden;          /* 隐藏溢出 */
  text-overflow: ellipsis;   /* 显示省略号 */
}

/* 多行省略(webkit)*/
.multi-ellipsis {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;     /* 显示3行 */
  overflow: hidden;
}

/* ④ 文字换行控制 */
.text-wrap {
  word-break: break-all;     /* 任意位置断行 */
  word-wrap: break-word;     /* 长单词断行 */
  overflow-wrap: break-word; /* 同word-wrap */
  white-space: pre-wrap;     /* 保留空白,自动换行 */
  hyphens: auto;             /* 自动断字符*/
}

/* ⑤ 文字渐变(配合background-clip)*/
.gradient-text {
  background: linear-gradient(135deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* ⑥ 字体特性 */
.font-features {
  font-variant-numeric: oldstyle-nums;  /*旧式数字 */
  font-variant-caps: small-caps;        /* 小型大写字母 */
  font-feature-settings: "liga" 1;      /* 连字 */
  font-kerning: auto;                   /* 字距调整 */
}

第五模块:过渡与动画 🎭

Transition 过渡
/* 基础过渡 */
.button {
  background: #3498db;
  color: white;
  padding: 10px 20px;
  border-radius: 4px;

  /* transition: 属性 时长缓动函数 延迟 */
  transition: all 0.3s ease;

  /* 多属性分别控制(更精细)*/
  transition:
    background 0.3s ease,
    transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.3s ease;
}

.button:hover {
  background: #2980b9;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
}

/* 缓动函数 */
.ease-demo {
  transition-timing-function: linear;                /* 匀速 */
  transition-timing-function: ease;/* 默认,慢快慢 */
  transition-timing-function: ease-in;                       /* 由慢到快 */
  transition-timing-function: ease-out;                      /* 由快到慢 */
  transition-timing-function: ease-in-out;                   /* 慢快慢 */
  transition-timing-function: cubic-bezier(0.68,-0.55,0.27,1.55); /* 自定义弹性 */
  transition-timing-function: steps(5, end);                 /* 步骤动画 */
}
Animation 动画
/* ① 定义关键帧 */
@keyframes slideInUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pulse {
  0%{ transform: scale(1); box-shadow: 0 0 0 0 rgba(52,152,219,0.7); }
  70%  { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(52,152,219,0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(52,152,219,0); }
}

@keyframes gradient-shift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ② 应用动画 */
.card-enter {
  animation: slideInUp 0.5s ease-out forwards;
}

.cta-button {
  /* animation:名称 时长 缓动 延迟 次数 方向 填充模式 状态 */
  animation: pulse 2s ease-in-out infinite;
}

.gradient-bg {
  background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
  background-size: 400% 400%;
  animation: gradient-shift 4s ease infinite;
}

/* ③ 动画控制 */
.animated-element {
  animation-name: slideInUp;
  animation-duration: 0.5s;
  animation-timing-function: ease-out;
  animation-delay: 0.2s;
  animation-iteration-count: infinite; /* 无限循环 */
  animation-direction: alternate;      /* 交替反向 */
  animation-fill-mode: forwards;       /* 保持结束状态 */
  animation-play-state: running;       /* running/paused */
}

/* ④ JS 控制动画 */
/* element.style.animationPlayState = 'paused'; */

第六模块:变换 Transform🔄

/* ① 2D 变换 */
.transform-2d {
  transform: translate(50px, 100px);  /* 位移 */
  transform: translateX(50px);
  transform: translateY(100px);

  transform: rotate(45deg);           /* 旋转 */
  transform: rotateX(45deg);          /* 沿X轴旋转 */

  transform: scale(1.5);/* 等比缩放 */
  transform: scaleX(1.5);            /* 水平缩放 */
  transform: scaleY(0.8);            /* 垂直缩放 */

  transform: skew(20deg, 10deg);     /* 倾斜 */
  transform: skewX(20deg);

  /* 链式组合(注意顺序影响结果!)*/
  transform: translateY(-50%) rotate(45deg) scale(1.2);
}

/* ② 3D 变换 */
.transform-3d {
  transform: perspective(500px) rotateY(30deg);
  transform: translateZ(100px);transform: rotate3d(1, 1, 0, 45deg);
  transform: scale3d(1.2, 1.2, 1.2);

  /* 透视(父元素设置)*/
  perspective: 1000px;perspective-origin: center center;

  /* 3D 空间保持 */
  transform-style: preserve-3d;

  /* 背面是否可见 */
  backface-visibility: hidden;

  /* 变换原点 */
  transform-origin: center center;
  transform-origin: left top;
  transform-origin: 0% 100%;
}

/* ③ 实际应用:翻转卡片 */
.flip-card {
  perspective: 1000px;
}

.flip-card-inner {
  transition: transform 0.6s;transform-style: preserve-3d;
  position: relative;
}

.flip-card:hover .flip-card-inner {
  transform: rotateY(180deg);
}

.flip-card-front,
.flip-card-back {
  backface-visibility: hidden;position: absolute;
  width: 100%;
  height: 100%;
}

.flip-card-back {
  transform: rotateY(180deg);
}

第七模块:布局系统 📐

Flexbox 弹性布局
/*父容器属性 */
.flex-container {
  display: flex;                /* 启用flex */
  flex-direction: row;                   /* 主轴方向:row/column/row-reverse/column-reverse */
  flex-wrap: wrap;                       /* 换行:nowrap/wrap/wrap-reverse */
  flex-flow: row wrap;                   /* 简写 */
  justify-content: space-between;        /* 主轴对齐:flex-start/center/space-between/space-around/space-evenly */
  align-items: center;                   /* 交叉轴单行对齐:flex-start/center/flex-end/stretch/baseline */
  align-content: space-between;          /* 交叉轴多行对齐 */
  gap: 16px;                             /* 子项间距 */
  gap: 16px 24px;                        /* 行间距 列间距 */
}

/* 子项属性 */
.flex-item {
  flex-grow: 1;      /* 放大比例,0为不放大 */
  flex-shrink: 1;    /* 缩小比例,0为不缩小 */
  flex-basis: 200px; /* 初始大小 */
  flex: 1;           /* 简写:flex-grow flex-shrink flex-basis = 11 0% */
  flex: 0 0 200px;   /* 固定宽不伸缩 */

  align-self: flex-end; /* 单独设置该子项对齐方式 */
  order: -1;            /* 排列顺序,默认0,越小越靠前 */
}

/* 经典应用:垂直水平居中 */
.center {
  display: flex;
  justify-content: center;
  align-items: center;
}
Grid 网格布局
/*父容器属性 */
.grid-container {
  display: grid;

  /* 定义列:3列等宽 */
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-columns: repeat(3, 1fr);
  grid-template-columns:200px 1fr 200px;  /* 两栏固定+中间自适应 */
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); /* 响应式卡片 */

  /* 定义行 */
  grid-template-rows: 60px 1fr 60px;
  grid-auto-rows: minmax(100px, auto);

  /* 间距 */
  gap: 16px;
  row-gap: 16px;
  column-gap: 24px;

  /* 命名区域 */
  grid-template-areas:
    "header  header  header"
    "sidebar main    main"
    "footer  footer  footer";
}

/* 子项属性 */
.header{ grid-area: header; }
.sidebar { grid-area: sidebar; }
.main    { grid-area: main; }
.footer  { grid-area: footer; }

/* 手动放置 */
.special-item {
  grid-column: 1 /3;    /* 从第1列线到第3列线(跨2列)*/
  grid-row: 2 / 4;       /* 从第2行线到第4行线(跨2行)*/
  grid-column: span 2;   /* 跨越2列 */
}

第八模块:颜色与渐变 🌈

/* ① 新颜色表示法 */
.colors {
  /* RGB + Alpha(透明度)*/
  color: rgba(52, 152, 219, 0.8);
  color: rgb(52 152 219 / 0.8);        /* 新语法(CSS4)*/

  /* HSL(更直观调色)*/
  color: hsl(204, 70%, 53%);
  color: hsla(204, 70%, 53%, 0.8);
  color: hsl(204 70% 53% / 0.8);       /* 新语法 */

  /* 现代颜色空间(CSS4)*/
  color: oklch(60% 0.15 230);/* 感知均匀色彩空间 */
  color: color(display-p3 0.5 0.5 1);  /* P3 广色域 */
}

/* ② 线性渐变 */
.linear-gradient {
  /* 基础 */
  background: linear-gradient(#3498db, #e74c3c);            /* 从上到下 */
  background: linear-gradient(to right, #3498db, #e74c3c);  /* 从左到右 */
  background: linear-gradient(135deg, #3498db, #e74c3c);/* 斜向*/

  /* 多色渐变 */
  background: linear-gradient(
    135deg,
    #667eea 0%,
    #764ba2 50%,
    #f093fb 100%
  );

  /* 硬边停止(无渐变)*/
  background: linear-gradient(
    to right,
    #3498db 50%,
    #e74c3c 50%     /* 50%处硬切换 */
  );
}

/* ③ 径向渐变 */
.radial-gradient {
  background: radial-gradient(circle, #3498db, #1a252f);
  background: radial-gradient(ellipse at top, #3498db, transparent);
  background: radial-gradient(
    circle at 30% 70%,
    #667eea 0%,
    #764ba2 60%,
    transparent 100%
  );
}

/* ④ 锥形渐变(CSS4)*/
.conic-gradient {
  background: conic-gradient(red, yellow, green, blue, red);  /* 色环 */
  background: conic-gradient(
    from 0deg,
    #3498db 0deg 90deg,
    #e74c3c 90deg 180deg,
    #2ecc71 180deg 270deg,
    #f39c12 270deg 360deg
  );

  /* 实现饼图 */
  border-radius: 50%;
}

/* ⑤ 重复渐变 */
.repeating-gradient {
  background: repeating-linear-gradient(
    45deg,
    #3498db 0px,
    #3498db 10px,
    white 10px,
    white 20px
  );/*斑马纹背景 */
}

第九模块:媒体查询与响应式 📱

/* ① 基础媒体查询 */
/*屏幕宽度 */
@media screen and (max-width: 768px) { /* 移动端 */ }
@media screen and (min-width: 769px) and (max-width: 1024px) { /* 平板 */ }
@media screen and (min-width: 1025px) { /* 桌面 */ }

/* ② 现代范围媒体查询(CSS4)*/
@media (width <= 768px) { /* 移动端 */ }
@media (768px < width <= 1024px) { /* 平板 */ }

/* ③ 其他媒体特性*/
@media print { body { font-size: 12pt; } }            /* 打印 */
@media (orientation: landscape) { /* 横屏 */ }         /* 屏幕方向 */
@media (prefers-color-scheme: dark) { /* 暗色模式 */ } /* 系统主题 */
@media (prefers-reduced-motion: reduce) { /* 减少动画 */ }
@media (hover: none) { /* 触屏设备,无悬停 */ }
@media (min-resolution: 2dppx) { /* 高清屏 Retina */ }
@media (display-mode: standalone) { /* PWA 独立模式 */ }

/* ④ 暗色模式实践 */
:root {
  --bg: #ffffff;
  --text: #333333;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --text: #f0f0f0;
  }
}

body {
  background: var(--bg);
  color: var(--text);
}

/* ⑤ 容器查询(CSS4,划时代新特性!)*/
.card-container {
  container-type: inline-size;/* 启用容器查询 */
  container-name: card;
}

@container card (min-width: 400px) {
  .card {
    display: flex;               /* 容器宽>400px 时变横向布局 */
    flex-direction: row;}
}

第十模块:其他重要特性 🧩

/* ① CSS 变量(自定义属性)*/
:root {
  --primary: #3498db;
  --shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.card {
  color: var(--primary);
  box-shadow: var(--shadow);
  box-shadow: var(--shadow, 0 2px 4px rgba(0,0,0,0.1)); /* 带默认值 */
}

/* ② calc() 计算函数 */
.sidebar {
  width: calc(100% - 240px);       /* 减去侧栏宽度 */
  height: calc(100vh - 60px);      /* 减去顶栏高度 */
  padding: calc(var(--space) * 2); /* 变量参与计算 */
}

/* ③ 滤镜 filter */
.filter-demo {
  filter: blur(4px);                /* 模糊 */
  filter: brightness(1.5);                   /* 亮度 */
  filter: contrast(1.2);                /* 对比度 */
  filter: grayscale(100%);                   /* 灰度 */
  filter: sepia(80%);                        /* 复古 */
  filter: hue-rotate(90deg);                 /* 色相旋转 */
  filter: invert(100%);                      /* 反色 */
  filter: opacity(0.5);                      /* 透明度 */
  filter: saturate(200%);                    /* 饱和度 */
  filter: drop-shadow(2px 2px 4px #000);    /* 投影(穿透透明)*/

  /* 组合多个滤镜 */
  filter: brightness(1.1) contrast(1.1) saturate(1.2);
}

/* backdrop-filter(背景滤镜,毛玻璃效果)*/
.glass-card {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px) saturate(180%);
  -webkit-backdrop-filter: blur(10px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* ④ object-fit(图片/视频填充方式)*/
.image-cover {
  width: 300px;
  height: 200px;
  object-fit: cover;    /* 覆盖裁剪(最常用)*/
  object-fit: contain;  /* 等比缩放,可能留白 */
  object-fit: fill;     /* 拉伸填满 */
  object-fit: none;     /* 原始尺寸 */
  object-position: center top; /* 焦点位置 */
}

/* ⑤ CSS Shapes(文字环绕形状)*/
.shape-wrap {
  float: left;
  shape-outside: circle(50%);        /* 文字沿圆形排列 */
  shape-outside: polygon(0 0, 100% 0, 50% 100%); /* 多边形 */
  shape-outside: url('shape.png');   /* 图片形状 */
  shape-margin: 10px;
}

/* ⑥ CSS 滚动吸附 */
.scroll-container {
  scroll-snap-type: x mandatory;    /* 横向强制吸附 */
  overflow-x: scroll;
}

.scroll-item {
  scroll-snap-align: start;/* 吸附到起始位置 */
  scroll-snap-align: center;        /* 吸附到中心 */
}

/* ⑦ 多列布局 */
.multi-column {
  column-count: 3;                   /* 3列 */
  column-width: 200px;              /* 列宽 */
  column-gap: 24px;                 /* 列间距 */
  column-rule: 1px solid #eee;      /* 分割线 */
  column-span: all;                 /* 子元素跨越所有列(标题)*/
}

/* ⑧ 逻辑属性(国际化)*/
.logical {
  /* 物理属性 → 逻辑属性 */
  margin-left: 16px;   /* → margin-inline-start */
  margin-right: 16px;  /* → margin-inline-end */
  margin-top: 16px;    /* → margin-block-start */
  padding-left: 16px;  /* → padding-inline-start */
  width: 100%;         /* → inline-size */
  height: 100%;        /* → block-size */
}

/* ⑨ 比较函数 */
.responsive {
  width: min(100%, 1200px);           /* 取最小值 */
  width: max(300px, 50%);            /* 取最大值 */
  width: clamp(300px, 50%, 1200px); /* 钳制在范围内 */
  font-size: clamp(14px, 2vw, 18px); /* 响应式字体!*/
}

/* ⑩ :is() / :where() / :has() 现代选择器 */
/* :is() 匹配列表中任一选择器(保留权重)*/
:is(h1, h2, h3, h4, h5, h6) {
  font-family: 'MyFont';
}

/* :where() 同is(),但权重为0 */
:where(header, main, footer) p {
  line-height: 1.6;
}

/* :has() 父元素选择器(CSS4,革命性!)*/
.card:has(img) {
  padding: 0;/* 有图片的卡片去掉padding */
}

li:has(+ li) {
  border-bottom: 1px solid; /* 非最后一个li加底边框 */
}

form:has(input:invalid) button[type="submit"] {
  opacity: 0.5;              /* 表单有不合法输入时,禁用提交按钮 */pointer-events: none;
}

##📊 CSS3 新特性全览表

特性分类 主要特性 重要程度
选择器 伪类、属性选择器、:not()、:has() ⭐⭐⭐⭐⭐
盒模型 box-sizing、box-shadow、border-radius ⭐⭐⭐⭐⭐
布局 Flexbox、Grid、多列 ⭐⭐⭐⭐⭐
动画 transition、animation、@keyframes ⭐⭐⭐⭐⭐
变换 transform 2D/3D ⭐⭐⭐⭐⭐
响应式 媒体查询、容器查询 ⭐⭐⭐⭐⭐
颜色渐变 rgba、hsl、linear/radial/conic-gradient ⭐⭐⭐⭐
背景 background-size、多背景、background-clip ⭐⭐⭐⭐
文字 @font-face、text-shadow、text-overflow ⭐⭐⭐⭐
滤镜 filter、backdrop-filter ⭐⭐⭐⭐
变量 CSS Variables(--var、var()) ⭐⭐⭐⭐⭐
函数 calc()、min()、max()、clamp() ⭐⭐⭐⭐
其他 object-fit、scroll-snap、:has() ⭐⭐⭐⭐

##📝 简答模板

适合时间紧张或非重点考察时


"CSS3 新特性非常多,我从几个最重要的方向来说:"

1. 选择器增强:新增了大量伪类选择器,如 :nth-child():not():has(),让选元素更精准。

2. 盒模型:新增 box-sizing: border-box,让宽高计算更直观;border-radius 实现圆角;box-shadow 实现阴影。

3. 视觉效果border-radius 圆角、box-shadow 阴影、text-shadow 文字阴影、filter 滤镜,以及 backdrop-filter 毛玻璃效果。

4. 过渡与动画transition 做简单过渡,animation + @keyframes 做复杂动画。

5. 变换transform 支持平移、旋转、缩放、倾斜,以及 3D 变换。

6. 布局革命Flexbox 解决一维布局,Grid 解决二维布局,彻底淘汰了float 布局。

7. 颜色与渐变:新增 rgbahsl颜色,linear-gradientradial-gradient 渐变。

8. 响应式@media 媒体查询,配合 clamp() 实现真正流体响应式设计。

9. CSS 变量--var 声明,var() 使用,支持 JS 动态修改,是现代主题系统基础。

10. 新字体@font-face 引入自定义字体,text-overflow: ellipsis 文字溢出省略。

/* 最能体现CSS3 特性的一段代码 */
.modern-card {
  /*盒模型 */
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);

  /* 渐变背景 */
  background: linear-gradient(135deg, #667eea, #764ba2);

  /* 变量*/
  padding: var(--spacing, 24px);

  /* 过渡 */
  transition: transform 0.3s ease, box-shadow 0.3s ease;

  /* 滤镜 */
  backdrop-filter: blur(10px);
}

.modern-card:hover {
  transform: translateY(-4px);           /* 变换 */
  box-shadow: 0 16px 48px rgba(0,0,0,0.15);
}

💡 一句话总结

CSS3 从"只能控制样式"进化到"能实现设计、动画、布局、响应式、交互",
核心亮点是:Flex/Grid 布局革命 + 动画体系 + 视觉效果增强 + 响应式能力,
让前端实现精美UI 不再依赖图片和 JS! 🚀

更多推荐