跳到主内容
UniKit

CSS 按钮生成器

在线可视化调试按钮样式并生成完整 CSS:纯色或线性渐变背景、文字颜色与字号字重、内边距、圆角、边框、阴影,以及 hover / active / disabled 三态差异与过渡曲线,预览按钮可真实悬停与按下。

浏览器本地运行所有计算都在你的浏览器里完成,数据不会离开本机。

预设样式

实心主色

背景类型

尺寸与边框

交互状态参数

按钮预览

把鼠标移到按钮上、按住不放,可以看到 hover / active 的真实效果;勾选下面开关查看 disabled。

当前状态: 默认 · 规则块: 4

生成的 CSS

包含 .button 与 :hover / :active / :disabled 四段规则,可直接复制。

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
  background: #2563eb;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
  cursor: pointer;
  transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.button:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
}

.button:active {
  transform: translateY(1px);
  filter: brightness(0.96);
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

这个工具能做什么

  • 快速试出一颗按钮:调背景(纯色/渐变)、字号字重、内边距、圆角、边框、阴影,再复制带三态的 CSS
  • 打磨 hover / active / disabled 细节:亮度、按下位移、禁用透明度、过渡时长与缓动都能调
  • 把设计稿参数搬进代码:颜色按 #hex 或 rgba 填,阴影按设计稿的 Y 偏移、模糊与颜色填

示例

输入

实心背景 #2563eb · 文字 #ffffff · 16px/600 · 内边距 12px 24px · 圆角 8px · 阴影 0 4px 12px rgba(37, 99, 235, 0.35) · 过渡 300ms cubic-bezier(0.4, 0, 0.2, 1)

输出

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
  background: #2563eb;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
  cursor: pointer;
  transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.button:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
}

.button:active {
  transform: translateY(1px);
  filter: brightness(0.96);
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

这是页面默认参数的真实输出;改任意一项,CSS 与左侧预览会同时更新。

常见问题

颜色支持哪些写法?

支持 #rgb / #rgba / #rrggbb / #rrggbbaa、rgb() / rgba(),以及 16 个 CSS 基础色关键字(black、white、red、transparent 等)。hsl()、颜色名如 rebeccapurple、渐变关键字都会报 invalid-color,不做静默兜底,避免生成浏览器不认的颜色。

hover / active / disabled 三态是怎么算的?

hover:filter: brightness(hover 亮度),启用阴影时把阴影加深(Y 偏移 +2px、模糊 +4px);active:translateY(下移量) 加 brightness(active 亮度);disabled:opacity(禁用透明度) + cursor: not-allowed + filter: none。亮度、下移量、透明度都在「交互状态参数」里可调,会真的写进对应的 :hover / :active / :disabled 规则。

预览和生成的 CSS 是同一份数据吗?

是。预览按钮的 :style 由 buttonStateStyle 算出,CSS 由 buildButtonCss 算出,两者读同一份参数与同一套校验;鼠标悬停、按住会真实切换到 hover / active,disabled 用开关预览,不会出现「预览好看、代码不对」。

生成的类名是什么?可以改吗?

页面固定输出 .button,方便直接粘贴;纯函数 buildButtonCss 支持第二个 selector 参数(必须是以 . 开头的类选择器),需要别的类名时可以改。本工具只生成 CSS,不生成 HTML 结构。

圆角能做成胶囊按钮吗?

可以,圆角上限是 999px,填 999 就是胶囊按钮(渐变胶囊预设就是这么做的)。边框宽度 0 时输出 border: 0,不会残留默认边框。

关键词:CSS 按钮生成器按钮样式hover 效果渐变按钮box-shadowCSS button generatorcss_buts

同类工具