1. 首页
  2. HTML/CSS

CSS高级使用-速查表

CSS 高级用法速查

渐变(Gradients)

线性渐变(Linear Gradient)

  • 语法background: linear-gradient(direction, color1, color2,...);

  • 示例background: linear-gradient(to right, red, yellow);

  • 描述:沿着指定方向在多种颜色间渐变。方向可用角度(如 45deg)或关键字(如 to top 等)。

径向渐变(Radial Gradient)

  • 语法background: radial-gradient(shape size at position, color1, color2,...);

  • 示例background: radial-gradient(circle at center, red, yellow);

  • 描述:从中心点向四周渐变。shape 可为 circleellipsesize 定义大小,position 定义中心位置 。

阴影(Shadows)

盒阴影(Box Shadow)

  • 语法box-shadow: h-offset v-offset blur-radius spread-radius color inset;

  • 示例box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.3);

  • 描述:为元素添加阴影。h-offset 水平偏移,v-offset 垂直偏移,blur-radius 模糊半径,spread-radius 扩展半径,color 阴影颜色,inset 表示内阴影。

文本阴影(Text Shadow)

  • 语法text-shadow: h-offset v-offset blur-radius color;

  • 示例text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);

  • 描述:为文本添加阴影,语法类似盒阴影但无 inset

转换(Transforms)

平移(Translate)

  • 语法transform: translate(x, y);transform: translateX(x);transform: translateY(y);

  • 示例transform: translate(50px, 100px);

  • 描述:移动元素位置,xy 可为像素值等,translateXtranslateY 分别控制水平和垂直平移。

缩放(Scale)

  • 语法transform: scale(x, y);transform: scaleX(x);transform: scaleY(y);

  • 示例transform: scale(1.5, 1.5);

  • 描述:改变元素大小,xy 为缩放比例,scaleXscaleY 分别控制水平和垂直缩放。

旋转(Rotate)

  • 语法transform: rotate(angle);

  • 示例transform: rotate(45deg);

  • 描述:围绕元素中心点旋转,角度可用多种单位。

倾斜(Skew)

  • 语法transform: skew(x-angle, y-angle);transform: skewX(angle);transform: skewY(angle);

  • 示例transform: skew(30deg, 10deg);

  • 描述:改变元素形状使其在水平或垂直方向倾斜。

过渡(Transitions)

过渡属性(transition-property)

  • 语法transition-property: property; (可多个属性用逗号分隔,也可用 all

  • 示例transition-property: background-color, transform;

  • 描述:指定哪些 CSS 属性变化时有过渡效果。

过渡持续时间(transition-duration)

  • 语法transition-duration: time;

  • 示例transition-duration: 0.5s;

  • 描述:定义过渡效果完成所需时间。

过渡时间函数(transition-timing-function)

  • 语法transition-timing-function: func;

  • 示例transition-timing-function: ease-in-out;

  • 描述:定义过渡效果的速度曲线,常见值有 easelinear 等,也可用 cubic-bezier(n,n,n,n) 自定义。

过渡延迟时间(transition-delay)

  • 语法transition-delay: time;

  • 示例transition-delay: 0.2s;

  • 描述:定义过渡效果开始前的延迟时间。

可合并简写为:transition: property duration timing-function delay;

动画(Animations)

定义关键帧(@keyframes)

  • 语法

@keyframes animation-name {
  percentage {
    /* CSS 属性 */
  }
}
  • 示例

@keyframes myAnimation {
  0% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(100px);
  }
  100% {
    transform: translateX(0);
  }
}
  • 描述:定义动画在不同时间点的状态,percentage 可为 0%100% 间任意值。

动画名称(animation-name)

  • 语法animation-name: name;

  • 示例animation-name: myAnimation;

  • 描述:指定要应用的动画名称,对应 @keyframes 定义的名称。

动画持续时间(animation-duration)

  • 语法animation-duration: time;

  • 示例animation-duration: 3s;

  • 描述:定义动画播放的总时长。

动画时间函数(animation-timing-function)

  • 语法animation-timing-function: func;

  • 示例animation-timing-function: ease-in-out;

  • 描述:同过渡的时间函数,控制动画播放速度曲线。

动画延迟时间(animation-delay)

  • 语法animation-delay: time;

  • 示例animation-delay: 0.5s;

  • 描述:定义动画开始前的延迟时间。

动画播放次数(animation-iteration-count)

  • 语法animation-iteration-count: count;

  • 示例animation-iteration-count: infinite;

  • 描述:定义动画播放次数,可为数字或 infinite(无限循环)。

动画播放方向(animation-direction)

  • 语法animation-direction: direction;

  • 示例animation-direction: alternate;

  • 描述:控制动画播放方向,常见值有 normalreversealternatealternate-reverse

动画填充模式(animation-fill-mode)

  • 语法animation-fill-mode: mode;

  • 示例animation-fill-mode: forwards;

  • 描述:定义动画执行前后如何应用样式,常见值有 noneforwardsbackwardsboth

可合并简写为:animation: name duration timing-function delay iteration-count direction fill-mode;


TOP